ToggleButton
ToggleButton and ButtonGroup.
This add-on adds Toggle functionality to Vaadin Buttons. It also includes a ButtonGroup manager which can create or register Buttons and manage the selection so that only one button is selected at a moment.
It includes 3 APIs:
- ToggleButton - Button with toggle capability.
- ToggleExtension - Extension to be used with a Button, adding toggle capability the Button.
- ButtonGroup - manage multiple buttons with a single button selected.
For now, adding the Buttons registered with a ButtonGroup on your UI is your responsibility. ButtonGroup only manages the selection so that only one button is selected.
Current beta version doesn't work with Valo. It was tested mainly against Reindeer.
By default the style of the selected state is the button pressed style, so in your scss file please move the @import and @include declarations of the togglebutton after the framework theme.
Sample code
// Buttons created by the ButtonGroup. ButtonGroup buttonGroup = new ButtonGroup("Island", "Language", "Cofee"); buttonGroup.addSelectionListener(new ButtonGroupSelectionListener() { @Override public void buttonGroupSelectionChanged( ButtonGroupSelectionEvent event) { Notification.show("You choosed " + event.getSelectedButton().getCaption()); } }); Button[] buttons = buttonGroup.getButtons(); for (Button button : buttons) { button.setWidth("100%"); } // Single ToggleButton. ToggleButton toggleButton = new ToggleButton("Pick me! Pick me!", new ToggleStateListener() { @Override public void toggleStateChanged(ToggleStateEvent event) { String caption = event.isButtonSelected() ? "Yes ;)" : "They changed my name ;("; event.getSource().getButton().setCaption(caption); } }); toggleButton.setWidth("100%"); // Place the buttons in a layout. VerticalLayout layout = new VerticalLayout(); layout.addComponent(new Label("Java is a:")); layout.addComponents(buttons); layout.addComponent(new Label("I want Oak:")); layout.addComponent(toggleButton); // Place yourself the layout somewhere ;)
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
- Released
- 2015-05-15
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.2+
- Browser
- Browser Independent