Class NullableToggleButtonModel

java.lang.Object
javax.swing.DefaultButtonModel
is.codion.swing.common.model.component.button.NullableToggleButtonModel
All Implemented Interfaces:
ItemSelectable, Serializable, ButtonModel

public final class NullableToggleButtonModel extends DefaultButtonModel
A ToggleButtonModel implementation, which allows the null state. The states are null -> false -> true. Heavily influenced by TristateCheckBox by Heinz M. Kabutz http://www.javaspecialists.eu/archive/Issue145.html Included with permission.
See Also:
  • Field Details

  • Constructor Details

    • NullableToggleButtonModel

      public NullableToggleButtonModel()
      Instantiates a new NullableToggleButtonModel with a null initial state.
    • NullableToggleButtonModel

      public NullableToggleButtonModel(Boolean initialState)
      Instantiates a new NullableToggleButtonModel with the given initial state.
      Parameters:
      initialState - the initial state
  • Method Details

    • isSelected

      public boolean isSelected()
      Specified by:
      isSelected in interface ButtonModel
      Overrides:
      isSelected in class DefaultButtonModel
      Returns:
      true if the underlying state is true
    • setSelected

      public void setSelected(boolean selected)
      Sets the underlying state to true or false
      Specified by:
      setSelected in interface ButtonModel
      Overrides:
      setSelected in class DefaultButtonModel
      Parameters:
      selected - the new state
    • setState

      public void setState(Boolean state)
      Sets the underlying state
      Parameters:
      state - the state
    • getState

      public Boolean getState()
      Returns the underlying value
      Returns:
      the state
    • nextState

      public void nextState()
      Iterates between the states: null -> false -> true
    • addListener

      public void addListener(Consumer<Boolean> listener)
      Adds a listener notified each time the state changes.
      Parameters:
      listener - the listener
    • removeListener

      public void removeListener(Consumer<Boolean> listener)
      Removes the given listener.
      Parameters:
      listener - the listener to remove