Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard GUI toggle switch in Java?

Is there a standard implementation or library that provides a GUI toggle switch in Swing? I know Swing provides a toggle button, but the UX leaves a bit to be desired. I'm looking for this:

enter image description here

Also, is there a canonical term for this type of control? The Apple HIG refer to it as a UISwitch. I also tried searching for "toggle switch", but I didn't have much luck. (Plenty of JavaScript results, but nothing native.)

like image 551
cbednarski Avatar asked Feb 05 '12 03:02

cbednarski


People also ask

How do you make a toggle button in Java?

We are using the following APIs. JToggleButton() − To create a toggle button. JToggleButton. isSelected() − To check if toggle button is currently in pressed state or not.

What is a toggle button in Java?

A toggle button allows the user to change a setting between two states. You can add a basic toggle button to your layout with the ToggleButton object.

Is Java GUI outdated?

Majority of existing GUI java codebases are Swing and likely will stay that way until the codebase rots and nobody maintains it anymore. Majority of new GUI java codebases are using JavaFX , which is the Swing replacement in Java8 and is part of the standard java library now.

Is Java Swing a GUI?

Swing is a GUI widget toolkit for Java. It is part of Oracle's Java Foundation Classes (JFC) – an API for providing a graphical user interface (GUI) for Java programs.


1 Answers

You might mimic it by using two icons to represent on & off, then set those to a JToggleButton.

As an aside, users want to see logical and consistent GUIs that represent the 'path of least surprise', it's developers that think users want a 'beautiful, clever' GUI (and that they can design one). Why on earth would they want such a control over a standard toggle-button?

like image 195
Andrew Thompson Avatar answered Sep 25 '22 02:09

Andrew Thompson