Binding text fields

You can use the Java visual editor to bind a Swing text field to a data object.
A JTextField can be bound to a particular property in a data object. For example, idTextField could be bound to the "id" property of a data object, while titleTextField could be bound to the "title" property of the same data object. For each text fields, a text field binder (SwingTextComponentBinder) is created to define the relationship between the text field and the data object.

The following screen shot shows an example text field bound to a data object.

Text field bound to a data object in the Java visual editor design area

To bind a text field to a data object:

  1. In the design area or Java Beans view, select a JTextField component.
  2. Click the Bind tab that displays on the JTextField in the design area. Alternatively, you can right-click the component in the Java Beans view and select Binding Properties from the pop-up menu. The Field Data Bindings dialog opens.
  3. In the Data objects list, select the data object that you want to use.

    If no data object exist for binding the text field, you can click New Data Source Data Object and define a new object.

    For more information, see Creating new data objects.

  4. In the Data object properties list, select the specific property that you want to bind the text field to.

    Field Data Bindings dialog box

  5. Click OK.
The design view displays the name of the property inside the text field, and if you select the text field, the visual editor draws a line connecting the field and the data object that it is bound to. The line also includes a small icon that represents the SwingTextComponentBinder.

Feedback