package javafxapplication9; import com.sun.javafx.runtime.VersionInfo; import javafx.application.Application; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableColumn.CellDataFeatures; import javafx.scene.control.TreeTableView; import javafx.scene.layout.HBox; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.util.Callback; public class JavaFXApplication9 extends Application { TreeTableView treeTableView; TreeTableColumn firstNameCol; @Override public void start(Stage primaryStage) { initTreeTableView(); HBox root = new HBox(10.0); root.getChildren().add(treeTableView); Button btnSetSortNode = new Button("Set sort node"); btnSetSortNode.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { firstNameCol.setSortNode(getSortNode(16, 16)); } }); root.getChildren().add(btnSetSortNode); Scene scene = new Scene(root, 400, 300); primaryStage.setTitle(VersionInfo.getRuntimeVersion()); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } private void initTreeTableView() { treeTableView = new TreeTableView<>(); treeTableView.setMinSize(200, 150); treeTableView.setPrefSize(200, 200); treeTableView.setMaxSize(200, 250); treeTableView.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY); TreeItem root = new TreeItem<>(new Person("John Smith", 32, (0xDEAFDEAD << 1) >>> 1)); treeTableView.setRoot(root); treeTableView.showRootProperty().set(true); firstNameCol = new TreeTableColumn<>("First name"); firstNameCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(TreeTableColumn.CellDataFeatures p) { return p.getValue().getValue().firstName; } }); firstNameCol.setMinWidth(100d); TreeTableColumn ageCol = new TreeTableColumn<>("Age"); ageCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures p) { return p.getValue().getValue().age; } }); ageCol.setMinWidth(100d); treeTableView.getColumns().addAll(firstNameCol, ageCol); Person p = new Person("Jessica Simpson", 33, 0xFEEBEE); treeTableView.getRoot().getChildren().add(new TreeItem<>(p)); p = new Person("Justin Beeber", 10, 0xBADBEAF); treeTableView.getRoot().getChildren().add(new TreeItem<>(p)); TreeTableColumn zipCol = new TreeTableColumn<>("Zip"); zipCol.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures p) { return p.getValue().getValue().zipCode; } }); zipCol.setMinWidth(100d); treeTableView.getColumns().add(zipCol); } private Node getSortNode(int width, int height) { return new Circle(Math.min(width, height) / 2, Color.RED); } } class Person { public final SimpleStringProperty firstName; public final SimpleIntegerProperty age; public final SimpleIntegerProperty zipCode; public Person(String name, int age, int zip) { this.firstName = new SimpleStringProperty(name); this.age = new SimpleIntegerProperty(age); zipCode = new SimpleIntegerProperty(zip); } }