Example usage for javafx.scene.control TreeTableView TreeTableView

List of usage examples for javafx.scene.control TreeTableView TreeTableView

Introduction

In this page you can find the example usage for javafx.scene.control TreeTableView TreeTableView.

Prototype

public TreeTableView(TreeItem<S> root) 

Source Link

Document

Creates a TreeTableView with the provided root node.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    final Scene scene = new Scene(new Group(), 200, 400);
    Group sceneRoot = (Group) scene.getRoot();

    TreeItem<String> childNode1 = new TreeItem<>("Node 1");
    TreeItem<String> childNode2 = new TreeItem<>("Node 2");
    TreeItem<String> childNode3 = new TreeItem<>("Node 3");

    TreeItem<String> root = new TreeItem<>("Root");
    root.setExpanded(true);/*from  w w w . j  a  v  a 2  s . c  om*/

    root.getChildren().setAll(childNode1, childNode2, childNode3);

    TreeTableColumn<String, String> column = new TreeTableColumn<>("Column");
    column.setPrefWidth(150);

    column.setCellValueFactory(
            (CellDataFeatures<String, String> p) -> new ReadOnlyStringWrapper(p.getValue().getValue()));

    TreeTableView<String> treeTableView = new TreeTableView<>(root);
    treeTableView.getColumns().add(column);
    sceneRoot.getChildren().add(treeTableView);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    root.setExpanded(true);/*from   ww  w.ja va  2s.c o  m*/
    employees.stream().forEach((employee) -> {
        root.getChildren().add(new TreeItem<>(employee));
    });
    Scene scene = new Scene(new Group(), 400, 400);
    Group sceneRoot = (Group) scene.getRoot();

    TreeTableColumn<Employee, String> empColumn = new TreeTableColumn<>("Employee");
    empColumn.setPrefWidth(150);
    empColumn.setCellValueFactory(
            (TreeTableColumn.CellDataFeatures<Employee, String> param) -> new ReadOnlyStringWrapper(
                    param.getValue().getValue().getName()));

    TreeTableColumn<Employee, String> emailColumn = new TreeTableColumn<>("Email");
    emailColumn.setPrefWidth(190);
    emailColumn.setCellValueFactory(
            (TreeTableColumn.CellDataFeatures<Employee, String> param) -> new ReadOnlyStringWrapper(
                    param.getValue().getValue().getEmail()));

    TreeTableView<Employee> treeTableView = new TreeTableView<>(root);
    treeTableView.getColumns().setAll(empColumn, emailColumn);

    treeTableView.setTableMenuButtonVisible(true);

    sceneRoot.getChildren().add(treeTableView);
    stage.setScene(scene);
    stage.show();
}