Class CheckBoxTreeCell<T>

java.lang.Object
Type Parameters:
T - The type of the elements contained within the TreeView TreeItem instances.
All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class CheckBoxTreeCell<T> extends TreeCell<T>
A class containing a TreeCell implementation that draws a CheckBox node inside the cell, along with support for common interactions (discussed in more depth shortly).

To make creating TreeViews with CheckBoxes easier, a convenience class called CheckBoxTreeItem is provided. It is highly recommended that developers use this class, rather than the regular TreeItem class, when constructing their TreeView tree structures. Refer to the CheckBoxTreeItem API documentation for an example on how these two classes can be combined.

When used in a TreeView, the CheckBoxCell is rendered with a CheckBox to the right of the 'disclosure node' (i.e. the arrow). The item stored in TreeItem.getValue() will then have the StringConverter called on it, and this text will take all remaining horizontal space. Additionally, by using CheckBoxTreeItem, the TreeView will automatically handle situations such as:

  • Clicking on the CheckBox beside an item that has children will result in all children also becoming selected/unselected.
  • Clicking on the CheckBox beside an item that has a parent will possibly toggle the state of the parent. For example, if you select a single child, the parent will become indeterminate (indicating partial selection of children). If you proceed to select all children, the parent will then show that it too is selected. This is recursive, with all parent nodes updating as expected.
If it is decided that using CheckBoxTreeItem is not desirable, then it is necessary to call one of the constructors where a Callback is provided that can return an ObservableValue<Boolean> given a TreeItem instance. This ObservableValue<Boolean> should represent the boolean state of the given TreeItem.

Note that the CheckBoxTreeCell renders the CheckBox 'live', meaning that the CheckBox is always interactive and can be directly toggled by the user. This means that it is not necessary that the cell enter its editing state (usually by the user double-clicking on the cell). A side-effect of this is that the usual editing callbacks (such as on edit commit) will not be called. If you want to be notified of changes, it is recommended to directly observe the boolean properties that are manipulated by the CheckBox.

Since:
JavaFX 2.2