Class CheckBoxTreeItem<T>

java.lang.Object
javafx.scene.control.TreeItem<T>
javafx.scene.control.CheckBoxTreeItem<T>
Type Parameters:
T - The type of the value contained within the TreeItem
All Implemented Interfaces:
EventTarget

public class CheckBoxTreeItem<T> extends TreeItem<T>
TreeItem subclass that adds support for being in selected, unselected, and indeterminate states. This is useful when used in conjunction with a TreeView which has a CheckBoxTreeCell installed.

A CheckBoxTreeItem can be independent or dependent. By default, CheckBoxTreeItem instances are dependent, which means that any changes to the selection state of a TreeItem will have an impact on parent and children CheckBoxTreeItem instances. If a CheckBoxTreeItem is set to be independent, this means that any changes to that CheckBoxTreeItem will not directly impact the state of parent and children CheckBoxTreeItem instances.

The indeterminate property is used to represent the same concept as that in CheckBox.indeterminateProperty(), namely, that the CheckBox is neither selected or unselected. This is commonly used inside a TreeView when some, but not all, of a branches children are selected.

A simple example of using the CheckBoxTreeItem class, in conjunction with CheckBoxTreeCell is shown below:

// create the tree model
 CheckBoxTreeItem<String> jonathanGiles = new CheckBoxTreeItem<>("Jonathan");
 CheckBoxTreeItem<String> juliaGiles = new CheckBoxTreeItem<>("Julia");
 CheckBoxTreeItem<String> mattGiles = new CheckBoxTreeItem<>("Matt");
 CheckBoxTreeItem<String> sueGiles = new CheckBoxTreeItem<>("Sue");
 CheckBoxTreeItem<String> ianGiles = new CheckBoxTreeItem<>("Ian");

 CheckBoxTreeItem<String> gilesFamily = new CheckBoxTreeItem<>("Giles Family");
 gilesFamily.setExpanded(true);
 gilesFamily.getChildren().addAll(jonathanGiles, juliaGiles, mattGiles, sueGiles, ianGiles);

 // create the treeView
 final TreeView<String> treeView = new TreeView<>();
 treeView.setRoot(gilesFamily);

 // set the cell factory
 treeView.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
Image of the CheckBoxTreeItem control
Since:
JavaFX 2.2
See Also: