Example usage for javafx.scene.control.cell CheckBoxTreeCell forTreeView

List of usage examples for javafx.scene.control.cell CheckBoxTreeCell forTreeView

Introduction

In this page you can find the example usage for javafx.scene.control.cell CheckBoxTreeCell forTreeView.

Prototype

public static <T> Callback<TreeView<T>, TreeCell<T>> forTreeView() 

Source Link

Document

Creates a cell factory for use in a TreeView control, although there is a major assumption when used in a TreeView: this cell factory assumes that the TreeView root, and all children are instances of CheckBoxTreeItem , rather than the default TreeItem class that is used normally.

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    CheckBoxTreeItem<String> rootItem = new CheckBoxTreeItem<>("A");
    rootItem.setExpanded(true);/*from w  w  w  . jav a 2  s.  c o  m*/

    TreeView tree = new TreeView(rootItem);
    tree.setEditable(true);

    tree.setCellFactory(CheckBoxTreeCell.forTreeView());

    CheckBoxTreeItem<String> checkBoxTreeItem = new CheckBoxTreeItem<>("a");
    rootItem.getChildren().add(checkBoxTreeItem);

    checkBoxTreeItem = new CheckBoxTreeItem<>("b");
    rootItem.getChildren().add(checkBoxTreeItem);

    tree.setRoot(rootItem);

    StackPane root = new StackPane();
    root.getChildren().add(tree);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}