Class TreeTableColumn<S,T>

java.lang.Object
javafx.scene.control.TableColumnBase<TreeItem<S>,T>
javafx.scene.control.TreeTableColumn<S,T>
Type Parameters:
S - The type of the TableView generic type (i.e. S == TableView<S>)
T - The type of the content in all cells in this TableColumn.
All Implemented Interfaces:
Styleable, EventTarget

public class TreeTableColumn<S,T> extends TableColumnBase<TreeItem<S>,T> implements EventTarget
A TreeTableView is made up of a number of TreeTableColumn instances. Each TreeTableColumn in a TreeTableView is responsible for displaying (and editing) the contents of that column. As well as being responsible for displaying and editing data for a single column, a TreeTableColumn also contains the necessary properties to: When creating a TreeTableColumn instance, perhaps the two most important properties to set are the column text (what to show in the column header area), and the column cell value factory (which is used to populate individual cells in the column). This can be achieved using some variation on the following code:

 firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
     public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
         // p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row,
         // p.getValue().getValue() returns the Person instance inside the TreeItem<Person>
         return p.getValue().getValue().firstNameProperty();
     }
  });
 }
This approach assumes that the object returned from p.getValue().getValue() has a JavaFX ObservableValue that can simply be returned. The benefit of this is that the TableView will internally create bindings to ensure that, should the returned ObservableValue change, the cell contents will be automatically refreshed.

In situations where a TableColumn must interact with classes created before JavaFX, or that generally do not wish to use JavaFX APIs for properties, it is possible to wrap the returned value in a ReadOnlyObjectWrapper instance. For example:


 firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
     public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
         // p.getValue() returns the TreeItem<Person> instance for a particular TreeTableView row,
         // p.getValue().getValue() returns the Person instance inside the TreeItem<Person>
         return new ReadOnlyObjectWrapper(p.getValue().getValue().getFirstName());
     }
  });
 }
It is hoped that over time there will be convenience cell value factories developed and made available to developers. As of the JavaFX 2.0 release, there is one such convenience class: TreeItemPropertyValueFactory. This class removes the need to write the code above, instead relying on reflection to look up a given property from a String. Refer to the TreeItemPropertyValueFactory class documentation for more information on how to use this with a TableColumn. Finally, for more detail on how to use TableColumn, there is further documentation in the TableView class documentation.
Since:
JavaFX 8.0
See Also: