Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Prevent certain cells in TreeView from being selected!?

cshFeb 10 2012 — edited Feb 10 2012
Hi,

is it possible to prevent certain cells in a TreeView from being selected?

I have a TreeView and the TreeItem's on the first "depth" should not be selectable.

I tried to add an EventHandler to the tree item and caught Event.ANY, but no event was dispatched, when a cell was selected.

Comments

jsmith
Research eventFilters in combination with event.consume():
http://docs.oracle.com/javafx/2.0/api/javafx/scene/Node.html#addEventFilter%28javafx.event.EventType,%20javafx.event.EventHandler%29

Other ways to accomplish this may be via a custom selectionModel:
http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/SelectionModel.html
http://docs.oracle.com/javafx/2.0/api/javafx/scene/control/TreeView.html#setSelectionModel%28javafx.scene.control.MultipleSelectionModel%29

Or by adding a ChangeListener to the selectedItems property of a the default TreeView selectionModel and setting the items to not be selected if it is the at the first "depth".
1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 9 2012
Added on Feb 10 2012
1 comment
636 views