I want right click menu option in the tree root node(JavaFX). Could any one help me on this.
TreeItem<String> root = new TreeItem<>(""+selectedDirectory);
root.setExpanded(true);
locationTreeView.setRoot(root);
root.getChildren().addAll(
new TreeItem<>("Item 1"),
new TreeItem<>("Item 2"),
new TreeItem<>("Item 3")
);
You can perform the desired behaviour in two steps:
TreeCell
factory on yourTreeView
;TreeCell
of the root tree item.The following code defines the custom
TreeCell
factory:And, here is the implementation of a custom tree cell that attaches a context menu for the root tree item:
The following example ilustrates the use of both, cell factory and custom cell, together:
You can take a look at the
TreeView
tutorial to see other uses and examples related to this JavaFX control.