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<String>("Jonathan");
CheckBoxTreeItem<String> juliaGiles = new CheckBoxTreeItem<String>("Julia");
CheckBoxTreeItem<String> mattGiles = new CheckBoxTreeItem<String>("Matt");
CheckBoxTreeItem<String> sueGiles = new CheckBoxTreeItem<String>("Sue");
CheckBoxTreeItem<String> ianGiles = new CheckBoxTreeItem<String>("Ian");
CheckBoxTreeItem<String> gilesFamily = new CheckBoxTreeItem<String>("Giles Family");
gilesFamily.setExpanded(true);
gilesFamily.getChildren().addAll(jonathanGiles, juliaGiles, mattGiles, sueGiles, ianGiles);
// create the treeView
final TreeView<String> treeView = new TreeView<String>();
treeView.setRoot(gilesFamily);
// set the cell factory
treeView.setCellFactory(CheckBoxTreeCell.<String>forTreeView());
extends
<T> | The type of the value contained within the TreeItem |
CheckBoxTreeCell, TreeItem, CheckBox