Class CheckTreeView<T>

Type Parameters:
T - The type of the data in the TreeView.
All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class CheckTreeView<T> extends TreeView<T>
A simple UI control that makes it possible to select zero or more items within a TreeView without the need to set a custom cell factory or manually create boolean properties for each row - simply use the check model to request the current selection state.

Screenshot

The following screenshot shows the CheckTreeView with some sample data:
Screenshot of CheckTreeView

Code Example:

To create the CheckTreeView shown in the screenshot, simply do the following:

 
 // create the data to show in the CheckTreeView 
 CheckBoxTreeItem<String> root = new CheckBoxTreeItem<String>("Root");
 root.setExpanded(true);
 root.getChildren().addAll(
               new CheckBoxTreeItem<String>("Jonathan"),
               new CheckBoxTreeItem<String>("Eugene"),
               new CheckBoxTreeItem<String>("Henri"),
               new CheckBoxTreeItem<String>("Samir"));
 
 // Create the CheckTreeView with the data 
 final CheckTreeView<String> checkTreeView = new CheckTreeView<>(root);
       
 // and listen to the relevant events (e.g. when the checked items change).
 checkTreeView.getCheckModel().getCheckedItems().addListener(new ListChangeListener<TreeItem<String>>() {
      public void onChanged(ListChangeListener.Change<? extends TreeItem<String>> c) {
          System.out.println(checkTreeView.getCheckModel().getCheckedItems());
      }
 });
 
  • Property Details

    • checkModel

      public final ObjectProperty<CheckModel<TreeItem<T>>> checkModelProperty
      The check model provides the API through which it is possible to check single or multiple items within a CheckTreeView, as well as inspect which items have been checked by the user. Note that it has a generic type that must match the type of the CheckTreeView itself.
  • Constructor Details

    • CheckTreeView

      public CheckTreeView()
      Creates a new CheckTreeView instance with an empty tree of choices.
    • CheckTreeView

      public CheckTreeView(CheckBoxTreeItem<T> root)
      Creates a new CheckTreeView instance with the given CheckBoxTreeItem set as the tree root.
      Parameters:
      root - The root tree item to display in the CheckTreeView.
  • Method Details

    • updateCheckModel

      protected void updateCheckModel()
    • getItemBooleanProperty

      public BooleanProperty getItemBooleanProperty(int index)
      Returns the BooleanProperty for a given item index in the CheckTreeView. This is useful if you want to bind to the property.
    • setCheckModel

      public final void setCheckModel(CheckModel<TreeItem<T>> value)
      Sets the 'check model' to be used in the CheckTreeView - this is the code that is responsible for representing the selected state of each CheckBox - that is, whether each CheckBox is checked or not (and not to be confused with the selection model concept, which is used in the TreeView control to represent the selection state of each row)..
    • getCheckModel

      public final CheckModel<TreeItem<T>> getCheckModel()
      Returns the currently installed check model.
    • checkModelProperty

      public final ObjectProperty<CheckModel<TreeItem<T>>> checkModelProperty()
      The check model provides the API through which it is possible to check single or multiple items within a CheckTreeView, as well as inspect which items have been checked by the user. Note that it has a generic type that must match the type of the CheckTreeView itself.