Converts ValueModels to the ToggleButtonModel interface. Useful to bind
JToggleButton, JCheckBox and JCheckBoxMenuItem to a ValueModel.
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));
author: Karsten Lentzsch version: $Revision: 1.6 $ See Also: javax.swing.ButtonModel See Also: javax.swing.JCheckBox See Also: javax.swing.JCheckBoxMenuItem |