Module is.codion.swing.common.model
Class NullableToggleButtonModel
java.lang.Object
javax.swing.DefaultButtonModel
is.codion.swing.common.model.component.button.NullableToggleButtonModel
- All Implemented Interfaces:
ItemSelectable,Serializable,ButtonModel
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 express permission from the author, 2019.
- Author:
- Heinz M. Kabutz, Björn Darri Sigurðsson
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.DefaultButtonModel
actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask -
Method Summary
Modifier and TypeMethodDescriptionget()booleanvoidnext()Iterates between the states: false -> null -> truestatic NullableToggleButtonModelInstantiates a newNullableToggleButtonModelwith a null initial state.static NullableToggleButtonModelnullableToggleButtonModel(@Nullable Boolean initialState) Instantiates a newNullableToggleButtonModelwith the given initial state.voidvoidsetSelected(boolean selected) Sets the underlying state to true or falseMethods inherited from class javax.swing.DefaultButtonModel
addActionListener, addChangeListener, addItemListener, fireActionPerformed, fireItemStateChanged, fireStateChanged, getActionCommand, getActionListeners, getChangeListeners, getGroup, getItemListeners, getListeners, getMnemonic, getSelectedObjects, isArmed, isEnabled, isPressed, isRollover, removeActionListener, removeChangeListener, removeItemListener, setActionCommand, setArmed, setEnabled, setGroup, setMnemonic, setPressed, setRollover
-
Field Details
-
NULL
public static final int NULLThe item state NULL.- See Also:
-
-
Method Details
-
isSelected
public boolean isSelected()- Specified by:
isSelectedin interfaceButtonModel- Overrides:
isSelectedin classDefaultButtonModel- Returns:
- true if the underlying state is true
-
setSelected
public void setSelected(boolean selected) Sets the underlying state to true or false- Specified by:
setSelectedin interfaceButtonModel- Overrides:
setSelectedin classDefaultButtonModel- Parameters:
selected- the new state
-
get
- Returns:
- the toggle state
-
set
- Parameters:
state- the toggle state
-
next
public void next()Iterates between the states: false -> null -> true
This is the same order as used by macOS, win32, IntelliJ IDEA and on the web as recommended by W3C.
-
nullableToggleButtonModel
Instantiates a newNullableToggleButtonModelwith a null initial state. -
nullableToggleButtonModel
Instantiates a newNullableToggleButtonModelwith the given initial state.- Parameters:
initialState- the initial state
-