-
Notifications
You must be signed in to change notification settings - Fork 32
SwitchButton
lcaron edited this page Jul 7, 2015
·
1 revision
This is a switch button to pick one value.
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.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(final SelectionEvent e) {
System.out.println("Before clicking, the selection was... " + button.getSelection());
}
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
}
});
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
andunselectedBackgroundColor
: : 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
An example called SwitchButtonSnippet is available in the directory src/test/java/org/mihalis/opal/switchButton
This example is also available here : https://github.com/lcaron/opal/blob/master/src/test/java/org/mihalis/opal/switchButton/SwitchButtonSnippet.java