APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javafx.scene.control

public Class CheckBoxTreeItem<T>

extends TreeItem<T>
Class Inheritance
Type Parameters
<T>
The type of the value contained within the TreeItem
Imports
javafx.scene.control.cell.CheckBoxTreeCell, javafx.beans.property.BooleanProperty, .SimpleBooleanProperty, javafx.beans.value.ChangeListener, javafx.event.Event, .EventType, javafx.scene.Node

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());
Image of the CheckBoxTreeItem control
Since
JavaFX 2.2
See Also
CheckBoxTreeCell, TreeItem, CheckBox

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
CheckBoxTreeItem.TreeModificationEvent<
The type of the value contained within the value property.
T
>

A TreeModificationEvent class that works in a similar vein to the javafx.scene.control.TreeItem.TreeModificationEvent class, in that this event will bubble up the CheckBoxTreeItem hierarchy, until the parent node is null.

Field Summary

Modifier and TypeField and Description
private static final EventType<? extends Event>
private final BooleanProperty
private final BooleanProperty
private final BooleanProperty
private final ChangeListener<Boolean>
private static boolean
Inherited from javafx.scene.control.TreeItem:
childrenlastComparatorlastSortModepreviousExpandedDescendentCount

Constructor Summary

AccessConstructor and Description
public
CheckBoxTreeItem()

Creates an empty CheckBoxTreeItem.

public
CheckBoxTreeItem(T
The object to be stored as the value of this TreeItem.
value
)

Creates a CheckBoxTreeItem with the value property set to the provided object.

public
CheckBoxTreeItem(T
The object to be stored as the value of this CheckBoxTreeItem.
value
,
Node
The Node to show in the TreeView next to this CheckBoxTreeItem.
graphic
)

Creates a CheckBoxTreeItem with the value property set to the provided object, and the graphic set to the provided Node.

public
CheckBoxTreeItem(T
The object to be stored as the value of this CheckBoxTreeItem.
value
,
Node
The Node to show in the TreeView next to this CheckBoxTreeItem.
graphic
,
boolean
The initial value of the selected property.
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.

public
CheckBoxTreeItem(T
The object to be stored as the value of this CheckBoxTreeItem.
value
,
Node
The Node to show in the TreeView next to this CheckBoxTreeItem.
graphic
,
boolean
The initial value of the selected property.
selected
,
boolean
The initial value of the independent property
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 TypeMethod and Description
public static <
The type of the value contained within the TreeItem.
T
>
EventType<CheckBoxTreeItem.TreeModificationEvent<T>>

Returns:

the EventType used when the CheckBoxTreeItem selection / indeterminate state changes
checkBoxSelectionChangedEvent
()

An EventType used when the CheckBoxTreeItem selection / indeterminate state changes.

private void
fireEvent(CheckBoxTreeItem<T> item, boolean selectionChanged)

public final BooleanProperty

Returns:

the independent state property of this CheckBoxTreeItem
independentProperty
()

A BooleanProperty used to represent the independent state of this CheckBoxTreeItem.

public final BooleanProperty

Returns:

the indeterminate state property of this CheckBoxTreeItem
indeterminateProperty
()

A BooleanProperty used to represent the indeterminate state of this CheckBoxTreeItem.

public final boolean
public final boolean

Returns:

true if CheckBoxTreeItem is indeterminate state
isIndeterminate
()

Returns the indeterminate state of this CheckBoxTreeItem.

public final boolean

Returns:

true if CheckBoxTreeItem is selected
isSelected
()

Returns the selected state of this CheckBoxTreeItem.

public final BooleanProperty

Returns:

the selected state property of this CheckBoxTreeItem
selectedProperty
()

A BooleanProperty used to represent the selected state of this CheckBoxTreeItem.

public final void
setIndependent(boolean value)

public final void
setIndeterminate(boolean
the indeterminate state of this CheckBoxTreeItem
value
)

Sets the indeterminate state of this CheckBoxTreeItem.

public final void
setSelected(boolean
the selected state of this CheckBoxTreeItem
value
)

Sets the selected state of this CheckBoxTreeItem.

private void
private void
private void
Inherited from javafx.scene.control.TreeItem:
addEventFilteraddEventHandlerbranchCollapsedEventbranchExpandedEventbuildEventDispatchChainchildrenModificationEventexpandedItemCountChangeEventexpandedPropertygetChildrengetExpandedDescendentCountgetGraphicgetParentgetValuegraphicChangedEventgraphicPropertyisExpandedisLeafleafPropertynextSiblingnextSiblingparentPropertypreviousSiblingpreviousSiblingremoveEventFilterremoveEventHandlersetExpandedsetGraphicsetValuesorttoStringtreeNotificationEventvalueChangedEventvalueProperty

Field Detail

CHECK_BOX_SELECTION_CHANGED_EVENTback to summary
private static final EventType<? extends Event> CHECK_BOX_SELECTION_CHANGED_EVENT
independentback to summary
private final BooleanProperty independent
indeterminateback to summary
private final BooleanProperty indeterminate
selectedback to summary
private final BooleanProperty selected
stateChangeListenerback to summary
private final ChangeListener<Boolean> stateChangeListener
updateLockback to summary
private static boolean updateLock

Constructor Detail

CheckBoxTreeItemback to summary
public CheckBoxTreeItem()

Creates an empty CheckBoxTreeItem.

CheckBoxTreeItemback to summary
public CheckBoxTreeItem(T value)

Creates a CheckBoxTreeItem with the value property set to the provided object.

Parameters
value:T

The object to be stored as the value of this TreeItem.

CheckBoxTreeItemback to summary
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:T

The object to be stored as the value of this CheckBoxTreeItem.

graphic:Node

The Node to show in the TreeView next to this CheckBoxTreeItem.

CheckBoxTreeItemback to summary
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:T

The object to be stored as the value of this CheckBoxTreeItem.

graphic:Node

The Node to show in the TreeView next to this CheckBoxTreeItem.

selected:boolean

The initial value of the selected property.

CheckBoxTreeItemback to summary
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:T

The object to be stored as the value of this CheckBoxTreeItem.

graphic:Node

The Node to show in the TreeView next to this CheckBoxTreeItem.

selected:boolean

The initial value of the selected property.

independent:boolean

The initial value of the independent property

Method Detail

checkBoxSelectionChangedEventback to summary
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) {
          ...
     }
 });
 
Parameters
<T>
The type of the value contained within the TreeItem.
Returns:EventType<CheckBoxTreeItem.TreeModificationEvent<T>>

the EventType used when the CheckBoxTreeItem selection / indeterminate state changes

Annotations
@SuppressWarnings:unchecked
fireEventback to summary
private void fireEvent(CheckBoxTreeItem<T> item, boolean selectionChanged)
independentPropertyback to summary
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:BooleanProperty

the independent state property of this CheckBoxTreeItem

indeterminatePropertyback to summary
public final BooleanProperty indeterminateProperty()

A BooleanProperty used to represent the indeterminate state of this CheckBoxTreeItem.

Returns:BooleanProperty

the indeterminate state property of this CheckBoxTreeItem

isIndependentback to summary
public final boolean isIndependent()
isIndeterminateback to summary
public final boolean isIndeterminate()

Returns the indeterminate state of this CheckBoxTreeItem.

Returns:boolean

true if CheckBoxTreeItem is indeterminate state

isSelectedback to summary
public final boolean isSelected()

Returns the selected state of this CheckBoxTreeItem.

Returns:boolean

true if CheckBoxTreeItem is selected

selectedPropertyback to summary
public final BooleanProperty selectedProperty()

A BooleanProperty used to represent the selected state of this CheckBoxTreeItem.

Returns:BooleanProperty

the selected state property of this CheckBoxTreeItem

setIndependentback to summary
public final void setIndependent(boolean value)
setIndeterminateback to summary
public final void setIndeterminate(boolean value)

Sets the indeterminate state of this CheckBoxTreeItem.

Parameters
value:boolean

the indeterminate state of this CheckBoxTreeItem

setSelectedback to summary
public final void setSelected(boolean value)

Sets the selected state of this CheckBoxTreeItem.

Parameters
value:boolean

the selected state of this CheckBoxTreeItem

updateDownwardsback to summary
private void updateDownwards()
updateStateback to summary
private void updateState()
updateUpwardsback to summary
private void updateUpwards()
javafx.scene.control back to summary

public Class CheckBoxTreeItem.TreeModificationEvent<T>

extends Event
Class Inheritance
Type Parameters
<T>
The type of the value contained within the value property.

A TreeModificationEvent class that works in a similar vein to the javafx.scene.control.TreeItem.TreeModificationEvent class, in that this event will bubble up the CheckBoxTreeItem hierarchy, until the parent node is null.
Since
JavaFX 2.2

Field Summary

Modifier and TypeField and Description
public static final EventType<Event>
ANY

Hides javafx.event.Event.ANY.

Common supertype for all tree modification event types.
private final boolean
private static final long
private final transient CheckBoxTreeItem<T>
Inherited from javafx.event.Event:
consumedeventTypeNULL_SOURCE_TARGETtarget

Constructor Summary

AccessConstructor and Description
public
TreeModificationEvent(EventType<? extends Event>
the eventType
eventType
,
CheckBoxTreeItem<T>
the treeItem
treeItem
,
boolean
represents whether the selection has changed
selectionChanged
)

Creates a default TreeModificationEvent instance to represent the change in selection/indeterminate states for the given CheckBoxTreeItem instance.

Method Summary

Modifier and TypeMethod and Description
public CheckBoxTreeItem<T>

Returns:

The CheckBoxTreeItem that this event occurred upon.
getTreeItem
()

Returns the CheckBoxTreeItem that this event occurred upon.

public boolean

Returns:

has the CheckBoxTreeItem's indeterminate changed
wasIndeterminateChanged
()

Indicates the reason for this event is that the indeterminate state on the CheckBoxTreeItem changed (as opposed to it becoming selected or unselected).

public boolean

Returns:

has the CheckBoxTreeItem's selection changed
wasSelectionChanged
()

Indicates the reason for this event is that the selection on the CheckBoxTreeItem changed (as opposed to it becoming indeterminate).

Inherited from javafx.event.Event:
cloneconsumecopyForfireEventgetEventTypegetTargetisConsumed

Field Detail

ANYback to summary
public static final EventType<Event> ANY

Hides javafx.event.Event.ANY.

Common supertype for all tree modification event types.

selectionChangedback to summary
private final boolean selectionChanged
Annotations
@SuppressWarnings:doclint:missing
serialVersionUIDback to summary
private static final long serialVersionUID

Hides javafx.event.Event.serialVersionUID.

treeItemback to summary
private final transient CheckBoxTreeItem<T> treeItem

Constructor Detail

TreeModificationEventback to summary
public TreeModificationEvent(EventType<? extends Event> eventType, CheckBoxTreeItem<T> treeItem, boolean selectionChanged)

Creates a default TreeModificationEvent instance to represent the change in selection/indeterminate states for the given CheckBoxTreeItem instance.

Parameters
eventType:EventType<? extends Event>

the eventType

treeItem:CheckBoxTreeItem<T>

the treeItem

selectionChanged:boolean

represents whether the selection has changed

Method Detail

getTreeItemback to summary
public CheckBoxTreeItem<T> getTreeItem()

Returns the CheckBoxTreeItem that this event occurred upon.

Returns:CheckBoxTreeItem<T>

The CheckBoxTreeItem that this event occurred upon.

wasIndeterminateChangedback to summary
public boolean wasIndeterminateChanged()

Indicates the reason for this event is that the indeterminate state on the CheckBoxTreeItem changed (as opposed to it becoming selected or unselected).

Returns:boolean

has the CheckBoxTreeItem's indeterminate changed

wasSelectionChangedback to summary
public boolean wasSelectionChanged()

Indicates the reason for this event is that the selection on the CheckBoxTreeItem changed (as opposed to it becoming indeterminate).

Returns:boolean

has the CheckBoxTreeItem's selection changed