Top Description Inners Fields Constructors Methods
org.controlsfx.control

public Class CheckTreeView<T>

extends TreeView<T>
Class Inheritance
Type Parameters
<T>
The type of the data in the TreeView.
Imports
java.util.ArrayList, .List, java.util.function.Consumer, javafx.beans.property.BooleanProperty, .ObjectProperty, .SimpleObjectProperty, javafx.collections.FXCollections, .ObservableList, javafx.scene.control.CheckBox, .CheckBoxTreeItem, .TreeItem, .TreeView, javafx.scene.control.cell.CheckBoxTreeCell

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private ObjectProperty<CheckModel<TreeItem<T>>>
checkModel

Properties

Constructor Summary

AccessConstructor and Description
public
CheckTreeView()

Creates a new CheckTreeView instance with an empty tree of choices.

public
CheckTreeView(final CheckBoxTreeItem<T>
The root tree item to display in the CheckTreeView.
root
)

Creates a new CheckTreeView instance with the given CheckBoxTreeItem set as the tree root.

Method Summary

Modifier and TypeMethod and Description
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.

public final CheckModel<TreeItem<T>>
getCheckModel()

Returns the currently installed check model.

public BooleanProperty
getItemBooleanProperty(int index)

Returns the BooleanProperty for a given item index in the CheckTreeView.

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)..

protected void
Inherited from javafx.scene.control.TreeView:
cellFactoryPropertycreateDefaultSkinediteditablePropertyeditAnyEventeditCancelEventeditCommitEventeditingItemPropertyeditStartEventexpandedItemCountPropertyfixedCellSizePropertyfocusModelPropertygetCellFactorygetClassCssMetaDatagetControlCssMetaDatagetEditingItemgetExpandedItemCountgetFixedCellSizegetFocusModelgetNodeLevelgetOnEditCancelgetOnEditCommitgetOnEditStartgetOnScrollTogetRootgetRowgetSelectionModelgetTreeItemgetTreeItemLevelisEditableisShowRootlayoutChildrenonEditCancelPropertyonEditCommitPropertyonEditStartPropertyonScrollToPropertyqueryAccessibleAttributerefreshrootPropertyscrollToselectionModelPropertysetCellFactorysetEditablesetFixedCellSizesetFocusModelsetOnEditCancelsetOnEditCommitsetOnEditStartsetOnScrollTosetRootsetSelectionModelsetShowRootshowRootProperty

Field Detail

checkModelback to summary
private ObjectProperty<CheckModel<TreeItem<T>>> checkModel

Properties

Constructor Detail

CheckTreeViewback to summary
public CheckTreeView()

Creates a new CheckTreeView instance with an empty tree of choices.

CheckTreeViewback to summary
public CheckTreeView(final CheckBoxTreeItem<T> root)

Creates a new CheckTreeView instance with the given CheckBoxTreeItem set as the tree root.

Parameters
root:CheckBoxTreeItem<T>

The root tree item to display in the CheckTreeView.

Method Detail

checkModelPropertyback to summary
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.

getCheckModelback to summary
public final CheckModel<TreeItem<T>> getCheckModel()

Returns the currently installed check model.

getItemBooleanPropertyback to summary
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.

setCheckModelback to summary
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)..

updateCheckModelback to summary
protected void updateCheckModel()
org.controlsfx.control back to summary

private Class CheckTreeView.CheckTreeViewCheckModel<T>

extends Object
implements CheckModel<TreeItem<T>>
Class Inheritance
All Implemented Interfaces
org.controlsfx.control.CheckModel

Support classes

Field Summary

Modifier and TypeField and Description
private ObservableList<TreeItem<T>>
private final TreeItem<T>
private final CheckTreeView<T>
treeView

* Internal properties * *

Constructor Summary

AccessConstructor and Description
pack-priv
CheckTreeViewCheckModel(final CheckTreeView<T> treeView)

* Constructors * *

Method Summary

Modifier and TypeMethod and Description
public void
check(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.check.

Checks the given item in the control.

public void
checkAll()

Implements org.controlsfx.control.CheckModel.checkAll.

Checks all items in the control

public void
clearCheck(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.clearCheck.

Unchecks the given item in the control

public void
clearChecks()

Implements org.controlsfx.control.CheckModel.clearChecks.

Unchecks all items in the control

public ObservableList<TreeItem<T>>
getCheckedItems()

Implements org.controlsfx.control.CheckModel.getCheckedItems.

Returns a read-only list of the currently checked items in the control.

public int
getItemCount()

Implements org.controlsfx.control.CheckModel.getItemCount.

* Implementing abstract API * *

public boolean
isChecked(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.isChecked.

Returns true if the given item is checked in the control.

public boolean
isEmpty()

Implements org.controlsfx.control.CheckModel.isEmpty.

Returns true if there are no checked items in the control.

private void
iterateOverTree(Consumer<TreeItem<T>> consumer)

* Private Implementation * *

private void
processChildren(Consumer<TreeItem<T>> consumer, List<TreeItem<T>> children)

private void
processNode(Consumer<TreeItem<T>> consumer, TreeItem<T> node)

public void
toggleCheckState(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.toggleCheckState.

Toggles the check state for the given item in the control.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkedItemsback to summary
private ObservableList<TreeItem<T>> checkedItems
rootback to summary
private final TreeItem<T> root
treeViewback to summary
private final CheckTreeView<T> treeView

* Internal properties * *

Constructor Detail

CheckTreeViewCheckModelback to summary
pack-priv CheckTreeViewCheckModel(final CheckTreeView<T> treeView)

* Constructors * *

Method Detail

checkback to summary
public void check(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.check.

Doc from org.controlsfx.control.CheckModel.check.

Checks the given item in the control.

Annotations
@Override
checkAllback to summary
public void checkAll()

Implements org.controlsfx.control.CheckModel.checkAll.

Doc from org.controlsfx.control.CheckModel.checkAll.

Checks all items in the control

Annotations
@Override
clearCheckback to summary
public void clearCheck(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.clearCheck.

Doc from org.controlsfx.control.CheckModel.clearCheck.

Unchecks the given item in the control

Annotations
@Override
clearChecksback to summary
public void clearChecks()

Implements org.controlsfx.control.CheckModel.clearChecks.

Doc from org.controlsfx.control.CheckModel.clearChecks.

Unchecks all items in the control

Annotations
@Override
getCheckedItemsback to summary
public ObservableList<TreeItem<T>> getCheckedItems()

Implements org.controlsfx.control.CheckModel.getCheckedItems.

Doc from org.controlsfx.control.CheckModel.getCheckedItems.

Returns a read-only list of the currently checked items in the control.

Annotations
@Override
getItemCountback to summary
public int getItemCount()

Implements org.controlsfx.control.CheckModel.getItemCount.

* Implementing abstract API * *

Annotations
@Override
isCheckedback to summary
public boolean isChecked(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.isChecked.

Doc from org.controlsfx.control.CheckModel.isChecked.

Returns true if the given item is checked in the control.

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements org.controlsfx.control.CheckModel.isEmpty.

Doc from org.controlsfx.control.CheckModel.isEmpty.

Returns true if there are no checked items in the control.

Annotations
@Override
iterateOverTreeback to summary
private void iterateOverTree(Consumer<TreeItem<T>> consumer)

* Private Implementation * *

processChildrenback to summary
private void processChildren(Consumer<TreeItem<T>> consumer, List<TreeItem<T>> children)
processNodeback to summary
private void processNode(Consumer<TreeItem<T>> consumer, TreeItem<T> node)
toggleCheckStateback to summary
public void toggleCheckState(TreeItem<T> item)

Implements org.controlsfx.control.CheckModel.toggleCheckState.

Doc from org.controlsfx.control.CheckModel.toggleCheckState.

Toggles the check state for the given item in the control.

Annotations
@Override