How can i create a ToggleButton?

Hello,

I am quite new to Vaadin framework. How can i create a toggle button?

Thanks to everybody for helping.

Kornel

Hi,


styletoggler add-on
There are several options. You can implement a custom button by using the , or by implementing your own logic with
button.setStyleName(String)
and your own CSS styles. You can also use the
tgglbttn-v7
or the
ToggleButton
add-ons (both not compatible with the Valo theme), the
ToggleSelect add-on
, or the
Switch add-on
.

Hi Alejandro,

Thanks for the tip. Actually i want to Show/Hide HeaderRow of Grid when clicked togglebutton.

What would be the best way to do this?

You can set the visibility of the header using this method:
https://vaadin.com/api/com/vaadin/ui/Grid.html#setHeaderVisible-boolean-
Call it from a click listener.

you can create your own toggle button with the help of css style,first you set the css property by default and apply if else condition in your clicklistener(check the condition with the help of getStyleName() vaadin property),for your reference refer this code.

///to hide/show component.

leftLayout.addStyleName(“hide_sec”); //set the display none
lblbtn.addClickListener(new ClickListener() {

		@Override
		public void buttonClick(ClickEvent event) {
			// TODO Auto-generated method stub
			if(leftLayout.getStyleName().contains("hide_sec"))
			{
			leftLayout.removeStyleName("hide_sec");
			leftLayout.addStyleName("show_sec");
			}
			else 
			{
				leftLayout.removeStyleName("show_sec");
				leftLayout.addStyleName("hide_sec");
			}
		}
	});