JAVAFX Tree view with different context menu
I want to create a context menu for treeitems in a tree structure. The point is, I want to display different context menus for each treeItem. How to implement this?
Foe example. I want to create "Add Employee" for Acc Dept and "Add Supporter" for IT support.
Based on the treeitem name, a context menu needs to be displayed.
+3
source to share
1 answer
public TreeModel() {
MenuItem addMenuItem = new MenuItem("Create Tab");
addMenu.getItems().add(addMenuItem);
addMenuItem.setOnAction(new EventHandler() {
@Override
public void handle(Event t) {
TreeItem newEmployee =
new TreeItem<>("New Tab");
getTreeItem().getChildren().add(newEmployee);
}
});
contextMenuProperty().bind(
Bindings.when(Bindings.equal(itemProperty(),"TABS"))
.then(addMenu)
.otherwise((ContextMenu)null));
}
It works. @James many thanks for the great article :)
+2
source to share