I am writing a javafx user interface and would like to get the Node owner of the context menu from eventHandler for the MenuItem object that was clicked.
My code is:
TabPane tabPane = new TabPane(); Tab tab1 = new Tab(); Tab tab2 = new Tab(); tabPane.getTabs().addAll(tab1,tab2); ContextMenu contextMenu = new ContextMenu(); MenuItem menuItem = new MenuItem("Do Some Action"); menuItem.setOnAction(new EventHandler<ActionEvent>(){ @override public void handle(ActionEvent e){
What I would like to do is get a link to the tab in which it was selected by contextMenu.
I managed to get a link to what ContextMenu seems to be in MenuItem with the following code inside the handle method (ActionEvent e) for the menuItem eventHandler element:
ContextMenu menu = ((ContextMenu)((MenuItem)e.getSource()).getParentPopup());
My idea was to use the ContextMenu.getOwnerNode () method on the menu, and then there is a link to the tab, but when I start, I get a link to an element that I cannot understand.
The toString () method for the object returned by .getOwnerNode () returns "TabPaneSkin $ TabHeaderSkin $ 3 @ 14f59cef", which I cannot understand the value.
Is my approach to working in a chain appropriate until I get back to the Node rule or is there a completely different approach that works better?
All I need is the functionality of ContextMenu, and when MenuItem is clicked, I need to have a link to the tab for which ContextMenu was selected, so I can do cool things with it.
source share