Skip to content

Nebula Switch Buttons

Wim Jongman edited this page May 14, 2026 · 3 revisions

Switch Buttons

These widgets are a switch button and a tr--state switch button to pick one value which are a different graphical representation of a checkbox button.

Switch Button

image

Usage

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());
});

Customisation

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 — if true, the switch button's corners are round; if false, they are square
  • borderColor — if set, a border is displayed around the widget
  • focusColor — color of the button when it has focus
  • selectedForegroundColor and selectedBackgroundColor — text and background colors of the selected state
  • unselectedForegroundColor and unselectedBackgroundColor — text and background colors of the unselected state
  • buttonBorderColor, buttonBackgroundColor1 and buttonBackgroundColor2 — 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

Examples

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

Tri-State Switch Button

image

Clone this wiki locally