com.jgoodies.binding.adapter
public final class ToggleButtonAdapter extends javax.swing.JToggleButton.ToggleButtonModel
This adapter holds two values that represent the selected and the deselected state. These are used to determine the selection state if the underlying subject ValueModel changes its value. If the selection is set, the corresponding representant is written to the underlying ValueModel.
Constraints: The subject ValueModel must allow read-access to its value. Also, it is strongly recommended (though not required) that the underlying ValueModel provides only two values, for example Boolean.TRUE and Boolean.FALSE. This is so because the toggle button component may behave "strangely" when it is used with ValueModels that provide more than two elements.
Examples:
// Recommended binding style using a factory ValueModel model = presentationModel.getModel(MyBean.PROPERTYNAME_VISIBLE); JCheckBox visibleBox = BasicComponentFactory.createCheckBox(model, "Visible"); // Binding using the Bindings class ValueModel model = presentationModel.getModel(MyBean.PROPERTYNAME_VISIBLE); JCheckBox visibleBox = new JCheckBox("Visible"); Bindings.bind(visibleBox, model); // Hand-made binding ValueModel model = presentationModel.getModel(MyBean.PROPERTYNAME_VISIBLE); JCheckBox visibleBox = new JCheckBox("Visible"); visibleBox.setModel(new ToggleButtonAdapter(model));
ButtonModel
,
JCheckBox
,
JCheckBoxMenuItem
,
Serialized FormConstructor and Description |
---|
ToggleButtonAdapter(ValueModel subject)
Constructs a ToggleButtonAdapter on the given subject ValueModel.
|
ToggleButtonAdapter(ValueModel subject,
java.lang.Object selectedValue,
java.lang.Object deselectedValue)
Constructs a ToggleButtonAdapter on the given subject ValueModel
using the specified values for the selected and deselected state.
|
Modifier and Type | Method and Description |
---|---|
void |
setSelected(boolean b)
First, the subject value is set to this adapter's selected value if
the argument is
true , to the deselected value otherwise. |
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
public ToggleButtonAdapter(ValueModel subject)
Boolean.TRUE
.subject
- the subject that holds the valuejava.lang.NullPointerException
- if the subject is null
.public ToggleButtonAdapter(ValueModel subject, java.lang.Object selectedValue, java.lang.Object deselectedValue)
selectedValue
.subject
- the subject that holds the valueselectedValue
- the value that will be set if this is selecteddeselectedValue
- the value that will be set if this is deselectedjava.lang.NullPointerException
- if the subject is null
.java.lang.IllegalArgumentException
- if the selected and deselected values
are equalpublic void setSelected(boolean b)
true
, to the deselected value otherwise.
Second, this adapter's state is set to the then current subject value.
This ensures that the selected state is synchronized with the subject
- even if the subject rejects the change.setSelected
in interface javax.swing.ButtonModel
setSelected
in class javax.swing.JToggleButton.ToggleButtonModel
b
- true
sets the selected value as subject value,
false
sets the deselected value as subject valueCopyright © 2002-2010 JGoodies Karsten Lentzsch. All Rights Reserved.