|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.binding.SwingBindingSupport
public final class SwingBindingSupport
SwingBindingSupport provides constants and documentation for
binding to Swing components. The following describes how to bind to
Swing components.
JCheckBox and specifying
it should not disable if the source path is incomplete:
Binding binding = new Binding(source, "sourcePath", jCheckBox, "selected",
SwingBindingSupport.DisableOnIncompletePathParameter, false);
JComboBox is a two phase process. You first bind
to the "elements" property. The "elements" property specifies the
contents of the JComboBox:
ListThe next step is to bind to the selection. There are two ways to do this. The first is to bind to an element of this list. This is useful if the object controlling the selection property is of the same type as that of the elements of thebugTypes; // Create the binding specifying the Binding binding = new Binding(bugTypes, null, jComboBox, "elements"); // Specify that each element is to be shown using the 'description' // property. If this is not specified, the elements in the list are // used used directly. binding.addBinding("description", null);
JComboBox:
Binding binding = new Binding(selection, "bugType",
jComboBox, "selectedElement");
// Specify that each element is to be shown using the 'description'
// property. If this is not specified, the elements in the list are
// used used directly.
binding.addBinding("description", null);
The second option is to bind the selection to a property of the elements
in the list. This involves binding to the "selectedElementProperty" and
specifying the expression to apply to each element when binding to the elements.
The following example illustrates this:
ListbugTypes; // Create the binding specifying the Binding binding = new Binding(bugTypes, null, jComboBox, "elements", // Specify that the "selectedElementProperty" corresponds to // selectedObject.id. SwingBindingSupport.ComboBoxSelectedObjectPropertyParameter, "${id}"); // Bind to the selection binding = new Binding(source, "id", jComboBox, "selectedElementProperty");
ListModel on the target JList. The source
property must resolve to a List. If the source property resolves
to an ObservableList, the ListModel tracks changes as
appropriate. A specific property can be specified for each element using
a child Binding. The following illustrates creating a binding
targetting a JList. The value for each element is obtained
using the 'firstName' property of each Customer.
ObservableListThe property delegate forcustomers; // Create the binding for the List. Binding binding = new Binding(customers, null, jList, "elements"); // Specify getValueAt is to return the 'firstName' property of // each element. binding.addBinding("firstName", null);
JList also provides support for the
"selectedElement" and "selectedElements" properties. The "selectedElement"
property corresponds to the selected element (in terms of an element of
the List bound to the "elements" property). The "selectedElements"
property is a List of the selected elements. Both values change
as the selection of the JList is modified.
JSlider. As disable
on incomplete path has not been specified, the slider disables if the
source path is incomplete.
Binding binding = new Binding(source, "sourcePath", jSlider, "value");
JTable provides similar properties to that of JList; the
"elements" properties, of type List, specifies the contents of
the JTable (or more correctly, the TableModel), and
the "selectedElement" and "selectedElements" properties may be used to
track changes in the selection. When binding to a JTable, you
must specify how the value for each column is obtained. This is done
using the binding property TableColumnParameter. The following
illustrates creating a binding targetting a JTable. Two columns
are created, the first using the property "firstName", and the second
"lastName".
ObservableListcustomers; // Create the binding for the List. Binding binding = new Binding(customers, null, jTable, "elements"); // Specify the first column should use the "firstName" property binding.addBinding("firstName", null, SwingBindingSupport.TableColumnParameter, 0); // Specify the second column should use the "lastName" property binding.addBinding("lastName", null, SwingBindingSupport.TableColumnParameter, 1);
TextChangeStrategyParameter.
The following illustrates creating a binding targetting a JTextField.
The "text" property of the JTextField is updated anytime the
Document of the JTextComponent changes.
Binding binding = new Binding(source, "sourcePath", jTextField, "text",
SwingBindingSupport.TextChangeStrategyParameter, CHANGE_ON_TYPE);
TreeModel). Use child bindings to specify how children of the root,
and other objects in the graph, are obtained. The child bindings must
resolve to Lists, and preferrably ObservableLists. The
following illustrates creating a binding targetting a JTree.
For nodes in the tree of type Manager, the "reports" property is
used to locate children.
Manager root;
Binding binding = new Binding(root, null, jTree, "root");
// For all nodes of type Manager, use the 'reports' property to find
// their children.
binding.addBinding("reports", null,
SwingBindingSupport.TreeNodeClassParameter, Manager.class);
| Nested Class Summary | |
|---|---|
static class |
SwingBindingSupport.TextChangeStrategy
An enumeration of the possible values for the TextChangeStrategyParameter of text components. |
| Field Summary | |
|---|---|
static Binding.Parameter<java.lang.String> |
ComboBoxSelectedObjectPropertyParameter
A Binding.Parameter used to specify whether the child binding
identifies the path for the "selectedObjectProperty" key of a
JComboBox. |
static Binding.Parameter<java.lang.Boolean> |
DisableOnIncompletePathParameter
A Binding.Parameter used to specify whether the target component
should disable itself when the source path is incomplete. |
static Binding.Parameter<java.lang.Boolean> |
EmptyNodeTreatedAsLeafParameter
A Binding.Parameter used to specify whether a node with no children
is treated as a leaf. |
static Binding.Parameter<java.lang.Class> |
TableColumnClassParameter
A Binding.Parameter used to specify the class of the table column. |
static Binding.Parameter<java.lang.Integer> |
TableColumnParameter
A Binding.Parameter used to specify the column the binding applies
to. |
static Binding.Parameter<SwingBindingSupport.TextChangeStrategy> |
TextChangeStrategyParameter
A Binding.Parameter used to specify when the "text" property of
text components should change. |
static Binding.Parameter<java.lang.Class> |
TreeNodeClassParameter
A Binding.Parameter used to specify the class a child binding
applies to. |
| Method Summary |
|---|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Binding.Parameter<SwingBindingSupport.TextChangeStrategy> TextChangeStrategyParameter
Binding.Parameter used to specify when the "text" property of
text components should change. If not specified, the default value is
CHANGE_ON_ACTION_OR_FOCUS_LOST.
Binding.setValue(Binding.Parameter,Object)public static final Binding.Parameter<java.lang.Boolean> DisableOnIncompletePathParameter
Binding.Parameter used to specify whether the target component
should disable itself when the source path is incomplete. If not
specified, the default is true. This property is supported for
JCheckBox's "selected" property, JSlider's "value"
property, and JTextComponent's "text" property.l
Binding.setValue(Binding.Parameter,Object)public static final Binding.Parameter<java.lang.Integer> TableColumnParameter
Binding.Parameter used to specify the column the binding applies
to. This is used on child bindings where the target is a JTable.
If not specified, an IllegalArgumentException is thrown when
bound.
Binding.setValue(Binding.Parameter,Object)public static final Binding.Parameter<java.lang.Class> TableColumnClassParameter
Binding.Parameter used to specify the class of the table column.
This is used on child bindings where the target is a JTable.
If not specified, the column class is treated as Object.class.
Binding.setValue(Binding.Parameter,Object)public static final Binding.Parameter<java.lang.Boolean> EmptyNodeTreatedAsLeafParameter
Binding.Parameter used to specify whether a node with no children
is treated as a leaf. The default is false.
Binding.setValue(Binding.Parameter,Object)public static final Binding.Parameter<java.lang.Class> TreeNodeClassParameter
Binding.Parameter used to specify the class a child binding
applies to. If not specified, an IllegalArgumentException is
thrown when bound.
Binding.setValue(Binding.Parameter,Object)public static final Binding.Parameter<java.lang.String> ComboBoxSelectedObjectPropertyParameter
Binding.Parameter used to specify whether the child binding
identifies the path for the "selectedObjectProperty" key of a
JComboBox. See the description of how to bind to
a JComboBox for more information.
Binding.setValue(Binding.Parameter,Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||