Class ToggleSwitch

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class ToggleSwitch extends JComponent
Modern toggle switch for ON/OFF (same visual language as RuleEngine; lives in shared-lib for reuse).
  • Constructor Details

    • ToggleSwitch

      public ToggleSwitch()
      An off switch, fixed at 44 x 22 px; a click toggles it.
    • ToggleSwitch

      public ToggleSwitch(boolean initialState)
      A switch in initialState.
  • Method Details

    • toggle

      public void toggle()
      Flips the state and runs the toggle callback (also what a click does).
    • isSelected

      public boolean isSelected()
      Whether the switch is on.
    • setSelected

      public void setSelected(boolean selected)
      Sets the state without running the toggle callback.
    • setOnToggle

      public void setOnToggle(Runnable callback)
      Runs on the EDT after each user toggle or toggle() call.
    • paintComponent

      protected void paintComponent(Graphics g)
      Paints the track and knob; green when on.
      Overrides:
      paintComponent in class JComponent