Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Nebula SwitchButton"
m (→Example) |
m (→Usage) |
||
Line 13: | Line 13: | ||
A switch button is a different graphic representation of a checkbox button. So the API is similar to the Button widget. You can get or set the selection,add selection listeners, enable or disable the button... | A switch button is a different graphic representation of a checkbox button. So the API is similar to the Button widget. You can get or set the selection,add selection listeners, enable or disable the button... | ||
− | + | final SwitchButton button = new SwitchButton(shell, SWT.NONE); | |
− | + | button.setText("Switch button..."); | |
− | final SwitchButton button = new SwitchButton(shell, SWT.NONE); | + | button.setTextForSelect("Selected..."); |
− | button.setText("Switch button..."); | + | button.setTextForUnselect("Unselected..."); |
− | button.setTextForSelect("Selected..."); | + | button.addListener(SWT.Selection, e-> { |
− | button.setTextForUnselect("Unselected..."); | + | System.out.println("Before clicking, the selection was... " + button.getSelection()); |
− | button. | + | }); |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | }); | + | |
− | + | ||
=Customisation= | =Customisation= |
Latest revision as of 08:09, 19 March 2020
Introduction
This is a switch button to pick one value.
Contents
Usage
A switch button is a different graphic representation of a checkbox button. So the API is similar to the Button widget. You can get or set the selection,add selection listeners, enable or disable the button...
final SwitchButton button = new SwitchButton(shell, SWT.NONE); button.setText("Switch button..."); button.setTextForSelect("Selected..."); button.setTextForUnselect("Unselected..."); button.addListener(SWT.Selection, e-> { System.out.println("Before clicking, the selection was... " + button.getSelection()); });
Customisation
By default, the button is grey, without border, with a blue background and 2 labels "On" and "Off". You can customize almost all elements of a switch button by setting the following properties :
-
textForSelect
: text associated to the selected state of the button -
textForUnselect
: text associated to the unselected state of the button -
text
: text displayed besides the button -
round
: if true, the switch button's corners are round. If false, the switch button's corners are square. -
borderColor
: if set, a border is displayed around the widget. -
focusColor
: Color of the button when the focus is on. -
selectedForegroundColor
andselectedBackgroundColor
: Color of the button (text color and background color) of the selected state of the button. -
unselectedForegroundColor and <code>unselectedBackgroundColor
: : text associated to the select state of the button -
buttonBorderColor
,buttonBackgroundColor1
andbuttonBackgroundColor1
: Colors of the button (border and gradient) -
gap
: gap between the button and the associated text -
foreground
,background
: foreground and background colors of the whole widget. -
font
: font of the widget
Example
An example called SwitchButtonSnippet is available in the directory org.eclipse.nebula.widgets.opal.switchbutton.snippets.
This example is also available here : SwitchButtonSnippet.java.