The JSwitchButton
and SwitchButtonUI
offer a toggle button that is rendered using a switch.
You can treat a JSwitchButton
like any other JToggleButton
:
JSwitchButton b = new JSwitchButton(); b.addChangeListener(changeListener);
The SwitchButtonUI
presents this button as a BasicRadioButtonUI
with an animating icon on the right hand side.
This kind of button was popularized by the rise of tablets/smartphones (and accompanying swipe gestures). As of this writing it looks to me like that switches exist occasionally on desktop computers, but they haven't really saturated desktop apps. (At least not yet.) When I look at the wifi and bluetooth menus on my Mac: the leading component is a switch button. But when I open the preferences for Pages: I see a sea of tabbed panes and checkboxes -- but no switches.
Functionally this is the same as a checkbox. It has a "selected" and "unselected" state. What's the difference? One website explains:
You should only use switches on settings that need to take effect instantaneously. If a setting requires a button press before it can take effect, you should use a checkbox instead.Another website more abstractly says checkboxes should be used for multiple characteristics, and switches better represent a binary on/off state.