0

I use the code from Ballage1551 from this post: Adapt TableView menu button

The problem: The CustomMenuItem ist filled with a Label-Node. But actions only work on clicking directly on the Label. It it is a short Label, there is a lot of area to the right without any use.

Any Idea how to make CutomMenuItem funtion as a MenuItem -> clicking anywhere in the MenuItems fires the event.

Thank you

Community
  • 1
  • 1
Hesk
  • 307
  • 4
  • 16
  • yes, create a group with a rectangle or pane as its backdrop then put the label on top of the group, set the action to the group instead thus it will see the pane/rectangle as part of the button and use its area as the button as well. – TravisF Mar 06 '17 at 23:05
  • Can't figure out how to implement what you wrote. Group/Pane don't have an setOnAction. Can you explain with an example Code maybe? – Hesk Mar 08 '17 at 21:01
  • yes, you can use the `group.setOnMouseEntered(new EventHandler() { @Override public void handle(MouseEvent e) { /* what you want it to do here */ }});` and to change on mouse out `group.setOnMouseExited` and `group.setOnMouseReleased` to make it do an action on release. The same works for Panes. – TravisF Mar 10 '17 at 04:50
  • It is not possible to add a Group to an ContextMenu. My code:`final ContextMenu cm = new ContextMenu(); final Group group = new Group(new Rectangle()); final Label test = new Label("Test"); group.getChildren().add(test); cm.getItems().add(group);` – Hesk Mar 10 '17 at 08:06

0 Answers0