Module javafx.controls
Package javafx.scene.control

# 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());

Since:
  JavaFX 2.2
See Also:
  - `CheckBoxTreeCell`
  - `TreeItem`
  - `CheckBox`

- ## Property Summary

  Properties
  Type
  Property
  Description
  `final BooleanProperty`
  `independent`
  A `BooleanProperty` used to represent the independent state of this CheckBoxTreeItem.
  `final BooleanProperty`
  `indeterminate`
  A `BooleanProperty` used to represent the indeterminate state of this CheckBoxTreeItem.
  `final BooleanProperty`
  `selected`
  A `BooleanProperty` used to represent the selected state of this CheckBoxTreeItem.

  ### Properties declared in class javafx.scene.control.TreeItem

  `expanded, graphic, leaf, parent, value`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `CheckBoxTreeItem.TreeModificationEvent<T>`
  A TreeModificationEvent class that works in a similar vein to the `TreeItem.TreeModificationEvent` class, in that this event will bubble up the CheckBoxTreeItem hierarchy, until the parent node is null.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CheckBoxTreeItem()`
  Creates an empty CheckBoxTreeItem.
  `CheckBoxTreeItem(T value)`
  Creates a CheckBoxTreeItem with the value property set to the provided object.
  `CheckBoxTreeItem(T value, Node graphic)`
  Creates a CheckBoxTreeItem with the value property set to the provided object, and the graphic set to the provided Node.
  `CheckBoxTreeItem(T value, Node graphic, boolean selected)`
  Creates a CheckBoxTreeItem with the value property set to the provided object, the graphic set to the provided Node, and the initial state of the `selectedProperty()` set to the provided boolean value.
  `CheckBoxTreeItem(T value, Node graphic, boolean selected, boolean independent)`
  Creates a CheckBoxTreeItem with the value property set to the provided object, the graphic set to the provided Node, the initial state of the `selectedProperty()` set to the provided boolean value, and the initial state of the `independent` property to the provided boolean value.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> EventType<CheckBoxTreeItem.TreeModificationEvent<T>>`
  `checkBoxSelectionChangedEvent()`
  An EventType used when the CheckBoxTreeItem selection / indeterminate state changes.
  `final BooleanProperty`
  `independentProperty()`
  A `BooleanProperty` used to represent the independent state of this CheckBoxTreeItem.
  `final BooleanProperty`
  `indeterminateProperty()`
  A `BooleanProperty` used to represent the indeterminate state of this CheckBoxTreeItem.
  `final boolean`
  `isIndependent()`
  Gets the value of the `independent` property.
  `final boolean`
  `isIndeterminate()`
  Returns the indeterminate state of this CheckBoxTreeItem.
  `final boolean`
  `isSelected()`
  Returns the selected state of this CheckBoxTreeItem.
  `final BooleanProperty`
  `selectedProperty()`
  A `BooleanProperty` used to represent the selected state of this CheckBoxTreeItem.
  `final void`
  `setIndependent(boolean value)`
  Sets the value of the `independent` property.
  `final void`
  `setIndeterminate(boolean value)`
  Sets the indeterminate state of this CheckBoxTreeItem.
  `final void`
  `setSelected(boolean value)`
  Sets the selected state of this CheckBoxTreeItem.

  ### Methods declared in class javafx.scene.control.TreeItem

  `addEventHandler, branchCollapsedEvent, branchExpandedEvent, buildEventDispatchChain, childrenModificationEvent, expandedItemCountChangeEvent, expandedProperty, getChildren, getGraphic, getParent, getValue, graphicChangedEvent, graphicProperty, isExpanded, isLeaf, leafProperty, nextSibling, nextSibling, parentProperty, previousSibling, previousSibling, removeEventHandler, setExpanded, setGraphic, setValue, toString, treeNotificationEvent, valueChangedEvent, valueProperty`

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Property Details

  - ### selected

    public final BooleanProperty selectedProperty
    A `BooleanProperty` used to represent the selected state of this CheckBoxTreeItem.
    See Also:
      - `isSelected()`
      - `setSelected(boolean)`
      - `selectedProperty()`

  - ### indeterminate

    public final BooleanProperty indeterminateProperty
    A `BooleanProperty` used to represent the indeterminate state of this CheckBoxTreeItem.
    See Also:
      - `isIndeterminate()`
      - `setIndeterminate(boolean)`
      - `indeterminateProperty()`

  - ### independent

    public final BooleanProperty independentProperty
    A `BooleanProperty` used to represent the independent state of this CheckBoxTreeItem. The independent state is used to represent whether changes to a single CheckBoxTreeItem should influence the state of its parent and children.

    By default, the independent property is false, which means that when a CheckBoxTreeItem has state changes to the selected or indeterminate properties, the state of related CheckBoxTreeItems will possibly be changed. If the independent property is set to true, the state of related CheckBoxTreeItems will never change.

    See Also:
      - `isIndependent()`
      - `setIndependent(boolean)`
      - `independentProperty()`

- ## Constructor Details

  - ### CheckBoxTreeItem

    public CheckBoxTreeItem()
    Creates an empty CheckBoxTreeItem.

  - ### CheckBoxTreeItem

    public CheckBoxTreeItem(T value)
    Creates a CheckBoxTreeItem with the value property set to the provided object.
    Parameters:
      `value` - The object to be stored as the value of this TreeItem.

  - ### CheckBoxTreeItem

    public CheckBoxTreeItem(T value, Node graphic)
    Creates a CheckBoxTreeItem with the value property set to the provided object, and the graphic set to the provided Node.
    Parameters:
      `value` - The object to be stored as the value of this CheckBoxTreeItem.
      `graphic` - The Node to show in the TreeView next to this CheckBoxTreeItem.

  - ### CheckBoxTreeItem

    public CheckBoxTreeItem(T value, Node graphic, boolean selected)
    Creates a CheckBoxTreeItem with the value property set to the provided object, the graphic set to the provided Node, and the initial state of the `selectedProperty()` set to the provided boolean value.
    Parameters:
      `value` - The object to be stored as the value of this CheckBoxTreeItem.
      `graphic` - The Node to show in the TreeView next to this CheckBoxTreeItem.
      `selected` - The initial value of the `selected` property.

  - ### CheckBoxTreeItem

    public CheckBoxTreeItem(T value, Node graphic, boolean selected, boolean independent)
    Creates a CheckBoxTreeItem with the value property set to the provided object, the graphic set to the provided Node, the initial state of the `selectedProperty()` set to the provided boolean value, and the initial state of the `independent` property to the provided boolean value.
    Parameters:
      `value` - The object to be stored as the value of this CheckBoxTreeItem.
      `graphic` - The Node to show in the TreeView next to this CheckBoxTreeItem.
      `selected` - The initial value of the `selected` property.
      `independent` - The initial value of the `independent` property

- ## Method Details

  - ### checkBoxSelectionChangedEvent

    public static <T> EventType<CheckBoxTreeItem.TreeModificationEvent<T>> checkBoxSelectionChangedEvent()
    An EventType used when the CheckBoxTreeItem selection / indeterminate state changes. To use this, it is recommended that you use code along the lines of the following:

         child1.addEventHandler(CheckBoxTreeItem.<String>checkBoxSelectionChangedEvent(), new EventHandler<TreeModificationEvent<String>>() {
             public void handle(TreeModificationEvent<String> event) {
                  ...
             }
         });

    Type Parameters:
      `T` - The type of the value contained within the TreeItem.
    Returns:
      the EventType used when the CheckBoxTreeItem selection / indeterminate state changes

  - ### setSelected

    public final void setSelected(boolean value)
    Sets the selected state of this CheckBoxTreeItem.
    Parameters:
      `value` - the selected state of this CheckBoxTreeItem

  - ### isSelected

    public final boolean isSelected()
    Returns the selected state of this CheckBoxTreeItem.
    Returns:
      true if CheckBoxTreeItem is selected

  - ### selectedProperty

    public final BooleanProperty selectedProperty()
    A `BooleanProperty` used to represent the selected state of this CheckBoxTreeItem.
    Returns:
      the selected state property of this CheckBoxTreeItem
    See Also:
      - `isSelected()`
      - `setSelected(boolean)`

  - ### setIndeterminate

    public final void setIndeterminate(boolean value)
    Sets the indeterminate state of this CheckBoxTreeItem.
    Parameters:
      `value` - the indeterminate state of this CheckBoxTreeItem

  - ### isIndeterminate

    public final boolean isIndeterminate()
    Returns the indeterminate state of this CheckBoxTreeItem.
    Returns:
      true if CheckBoxTreeItem is indeterminate state

  - ### indeterminateProperty

    public final BooleanProperty indeterminateProperty()
    A `BooleanProperty` used to represent the indeterminate state of this CheckBoxTreeItem.
    Returns:
      the indeterminate state property of this CheckBoxTreeItem
    See Also:
      - `isIndeterminate()`
      - `setIndeterminate(boolean)`

  - ### independentProperty

    public final BooleanProperty independentProperty()
    A `BooleanProperty` used to represent the independent state of this CheckBoxTreeItem. The independent state is used to represent whether changes to a single CheckBoxTreeItem should influence the state of its parent and children.

    By default, the independent property is false, which means that when a CheckBoxTreeItem has state changes to the selected or indeterminate properties, the state of related CheckBoxTreeItems will possibly be changed. If the independent property is set to true, the state of related CheckBoxTreeItems will never change.

    Returns:
      the independent state property of this CheckBoxTreeItem
    See Also:
      - `isIndependent()`
      - `setIndependent(boolean)`

  - ### setIndependent

    public final void setIndependent(boolean value)
    Sets the value of the `independent` property.
    Property description:
      A `BooleanProperty` used to represent the independent state of this CheckBoxTreeItem. The independent state is used to represent whether changes to a single CheckBoxTreeItem should influence the state of its parent and children.

      By default, the independent property is false, which means that when a CheckBoxTreeItem has state changes to the selected or indeterminate properties, the state of related CheckBoxTreeItems will possibly be changed. If the independent property is set to true, the state of related CheckBoxTreeItems will never change.

    Parameters:
      `value` - the value for the `independent` property
    See Also:
      - `isIndependent()`
      - `independentProperty()`

  - ### isIndependent

    public final boolean isIndependent()
    Gets the value of the `independent` property.
    Property description:
      A `BooleanProperty` used to represent the independent state of this CheckBoxTreeItem. The independent state is used to represent whether changes to a single CheckBoxTreeItem should influence the state of its parent and children.

      By default, the independent property is false, which means that when a CheckBoxTreeItem has state changes to the selected or indeterminate properties, the state of related CheckBoxTreeItems will possibly be changed. If the independent property is set to true, the state of related CheckBoxTreeItems will never change.

    Returns:
      the value of the `independent` property
    See Also:
      - `setIndependent(boolean)`
      - `independentProperty()`