dd.ui
Class JBoolean
java.lang.Object
javax.swing.DefaultButtonModel
javax.swing.JToggleButton.ToggleButtonModel
dd.ui.JBoolean
- All Implemented Interfaces:
- javax.swing.ButtonModel, java.awt.ItemSelectable, java.io.Serializable
- public class JBoolean
- extends javax.swing.JToggleButton.ToggleButtonModel
A bound boolean variable. You can use this class to easily deal with
boolean variables within Swing interfaces. This "model" can be associated
with as many swing components as necessary, but usually it is displayed in
only one check box or radio button. GUI events will update this boolean
value, and updating the boolean will update any radio buttons or check
boxes that use this as a model.
You must set the "model" of the button before any use of the button.
Example usage (checkbox)
JBoolean bold = new JBoolean();
JCheckBox useBold = new JCheckBox("Bold Text");
useBold.setModel(bold);
bold.setState(true); // Also sets the checkbox
bold.getState(); // returns the current state of the checkbox
Example usage (radio buttons)
JBoolean size10, size12, size14;
size10 = new JBoolean();
size12 = new JBoolean();
size14 = new JBoolean();
JRadioButton use10, use12, use14;
JButtonGroup bg = new ButtonGroup();
use10 = new JRadioButton("10 point");
use10.setModel(size10);
bg.add(use10);
use12 = new JRadioButton("12 point");
use12.setModel(size12);
bg.add(use12);
use14 = new JRadioButton("14 point");
use14.setModel(size14);
bg.add(use10);
size12.setState(true);
size12.getState(); // will return "true"
size10.getState(); // will return "false"
size10.setState(true);
size12.getState(); // will return "false"
size10.getState(); // will return "true"
- Author:
- Eric Scharff
- See Also:
- Serialized Form
Fields inherited from class javax.swing.DefaultButtonModel |
actionCommand, ARMED, changeEvent, ENABLED, group, listenerList, mnemonic, PRESSED, ROLLOVER, SELECTED, stateMask |
Method Summary |
boolean |
getState()
Returns the state of the boolean value. |
void |
setSelected(boolean state)
Updates the state of the boolean value. |
void |
setState(boolean state)
Updates the state of the boolean value. |
Methods inherited from class javax.swing.JToggleButton.ToggleButtonModel |
isSelected, setPressed |
Methods 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, setRollover |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JBoolean
public JBoolean()
getState
public boolean getState()
- Returns the state of the boolean value. This state will always be in
sync with the GUI representation (or multiple representations) of the
boolean.
- Returns:
true
if the boolean is "checked" or "selected".
setState
public void setState(boolean state)
- Updates the state of the boolean value. This state will be propagated
to any GUI components that listen for the button. Setting this to
true
indicates that the boolean is "checked" or
"selected".
- Parameters:
state
- true
if the boolean is "selected"
setSelected
public void setSelected(boolean state)
- Updates the state of the boolean value. This state will be propagated
to any GUI components that listen for the button. Setting this to
true
indicates that the boolean is "checked" or
"selected". This overrides the default behavior for Swing button
models to properly store the new selected value.
- Parameters:
state
- true
if the boolean is "selected"