The table classes provide built-in capabilities to sort data in columns and to resize columns when necessary. Example 12-3 creates the data = FXCollections.observable Array List( new Person("Jacob", "Smith", "[email protected]"), new Person("Isabella", "Johnson", "[email protected]"), new Person("Ethan", "Williams", "[email protected]"), new Person("Emma", "Jones", "[email protected]"), new Person("Michael", "Brown", "[email protected]") ); import javafx.application.
Figure 12-1 shows a typical table representing contact information from an address book.
Note that the first column has priority over the second column.
In this chapter, you learn how to perform basic operations with tables in Java FX applications, such as adding a table, populating the table with data, and editing table rows. Compiling and running this application produces the output shown in Figure 12-2. When the structure of your data requires a more complicated representation, you can create nested columns.
Several classes in the Java FX SDK API are designed to represent data in a tabular form. For example, suppose that the contacts in the address book have two email accounts.
You can create a new table without rows by using the CREATE TABLE statement to define the columns and their attributes.
You can specify a column's name, type, length, informat, format, and label.
Example 12-7 creates three text fields, defines the prompt text for each field, and creates the Add button.