Java Reference
In-Depth Information
Problem
You want to display items in a UI table control similar to Java Swing's
JTable
com-
ponent.
Solution
Create an application using JavaFX's
javafx.scene.control.TableView
class. The
TableView
control provides the equivalent functionality to Swing's
JT-
able
component.
To exercise the
TableView
control you will be creating an application that will
display bosses and employees. On the left you will implement a
ListView
control
containing bosses, and employees (subordinates) will be displayed in a
TableView
control on the right.
Shown here is the source code of a simple domain (
Person
) class to represent a
boss or an employee to be displayed in a
ListView
or
TableView
control:
package org.java7recipes.chapter15.recipe15_14;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class Person {
private StringProperty aliasName;
private StringProperty firstName;
private StringProperty lastName;
private ObservableList<Person> employees
= FXCollections.observableArrayList();
public final void setAliasName(String value) {
aliasNameProperty().set(value);
}
public final String getAliasName() {