Binding tables

You can use the visual editor to bind a Swing JTable to a row data object.

If you have a JTable in your application, you can bind the table to be populated by a row data object. For example, you might have a table in your application where you want to list all company employees, with their employee ID, last name, and first name. You have available to you a service (for example, an enterprise bean or a Web service) that returns an array of employees with a set of properties for each employee. You could bind that table to the data source row object that represents the data provided by the service. Each object in the array might include more properties than you want to display for each employee in the table, so you can specify the properties that you want to map to columns in your visual table.

When you bind a JTable to a row data object, the visual editor generates the appropriate classes and interfaces into a new package (the default package name is jve.generated, but this can be changed in the Java visual editor preferences), and it creates a new instance of a JRowTableBinder, which defines the binding between the JTable and the data object. Some of the capabilities of a JRowTableBinder include the following:

To bind a JTable to a row data object:

  1. In the design area or Java Beans view, select a JTable component.

  2. Click the Bind tab that displays on the JTable 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 Table Data Bindings dialog opens.

  3. In the Data objects list, select the data object that you want to use. Possible data objects that you can select here are instances of RowDataObject or IDataObject. An IDataObject only appears in the list if it contains one or more array properties that can be bound to the table. Only those array properties (and the branches required to navigate to them) are displayed in the object tree.

    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 properties that you want to map to the table columns, and use the arrow buttons to move them to the Table columns list.

  5. Optional: In the Table columns list, select each property name and type a new display name in the Column title column. The values that you type for the column titles are used in your application as the table column headers.

  6. Optional: In the Table columns list, select a property and use the up and down arrow buttons to reorder the columns. The first property listed in the Table columns list will be the first column in the visual table.

  7. Click OK.

The following screen shot shows a table that is bound to a data object that gets its data from a Web service data source. Notice the line indicating that the table is bound to the data object. The line also includes an icon that represents the JRowTableBinder, which is used by the table as its binding model.

 

Parent topic

Binding Java visual components to data with the visual editor