-
Notifications
You must be signed in to change notification settings - Fork 105
Nebula Switch Buttons
Wim Jongman edited this page May 14, 2026
·
3 revisions
These widgets are a switch button and a tr-state switch button to pick one value — a different graphical representation of a checkbox button.
The API is similar to the Button widget. You can get or set the selection, add selection listeners, enable or disable the button, etc.
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());
});By default, the button is grey, without border, with a blue background and two labels "On" and "Off". You can customise 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 beside the button -
round— iftrue, the switch button's corners are round; iffalse, they are square -
borderColor— if set, a border is displayed around the widget -
focusColor— color of the button when it has focus -
selectedForegroundColorandselectedBackgroundColor— text and background colors of the selected state -
unselectedForegroundColorandunselectedBackgroundColor— text and background colors of the unselected state -
buttonBorderColor,buttonBackgroundColor1andbuttonBackgroundColor2— colors of the toggle 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
An example called SwitchButtonSnippet.java is located in the plugin org.eclipse.nebula.widgets.opal.switchbutton.snippets.
This example is also available here: SwitchButtonSnippet.java