Class ToggleButton

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, SwingConstants

public class ToggleButton extends JCheckBox
A styled checkbox component that displays as an on/off toggle switch.

ToggleButton extends JCheckBox but displays as a graphical toggle switch rather than a traditional checkbox. It uses Storm's brand purple color when enabled and grayscale when disabled.

The button can optionally store an associated object, which is useful when using toggle buttons in lists or for enum values.

Example usage:


 // Simple toggle
 ToggleButton toggle = new ToggleButton();
 toggle.setSelected(true);

 // Toggle with label
 ToggleButton labeledToggle = new ToggleButton("Enable Feature");

 // Toggle for enum value
 ToggleButton enumToggle = new ToggleButton(MyEnum.OPTION_A);
 MyEnum value = (MyEnum) enumToggle.getObject();
 

See Also:
  • Constructor Details

    • ToggleButton

      public ToggleButton()
      Creates a new toggle button with no label or associated object.
    • ToggleButton

      public ToggleButton(String text)
      Creates a new toggle button with the specified label.
      Parameters:
      text - the label text to display
    • ToggleButton

      public ToggleButton(Object object)
      Creates a new toggle button for an enum value.

      The button's label is set to the title case version of the enum name. The object can be retrieved later using getObject().

      Parameters:
      object - the enum value to associate with this button
  • Method Details

    • getObject

      public Object getObject()
      Gets the object associated with this toggle button.
      Returns:
      the associated object, or null if none was set