autoCompletePopup.getItems().get(focusIdx).getOnAction().handle(new ActionEvent());
private void keyPressed(KeyEvent event) { for (MenuItem mi : tabPane.getContextMenu().getItems()) { if (mi.getAccelerator()!=null && mi.getAccelerator().match(event)) { mi.getOnAction().handle(null); event.consume(); return; } } }
CirclePopupMenuNode (MenuItem menuItem) { this.menuItem = menuItem; setId(this.getClass().getSimpleName() + "#" + menuNodeIdAtomicLong.incrementAndGet()); // show the graphical part if (menuItem.getGraphic() == null) { throw new NullPointerException("MenuItems in CirclePopupMenu require a graphical part, text is optional"); } getChildren().add(menuItem.getGraphic()); // show the text as a tooltip if (menuItem.getText() != null && menuItem.getText().length() > 0) { Tooltip t = new Tooltip(menuItem.getText()); Tooltip.install(this, t); } // react on a mouse click to perform the menu action setOnMouseClicked( (eventHandler) -> { hide(); if (menuItem.getOnAction() != null) { menuItem.getOnAction().handle(null); } }); } final private MenuItem menuItem;
CornerMenuNode (MenuItem menuItem) { this.menuItem = menuItem; setId(this.getClass().getSimpleName() + "#" + menuNodeIdAtomicLong.incrementAndGet()); // show the graphical part if (menuItem.getGraphic() == null) { throw new NullPointerException("MenuItems in CornerMenu require a graphical part, text is optional"); } getChildren().add(menuItem.getGraphic()); // show the text as a tooltip if (menuItem.getText() != null && menuItem.getText().length() > 0) { Tooltip t = new Tooltip(menuItem.getText()); Tooltip.install(this, t); } // react on a mouse click to perform the menu action setOnMouseClicked( (eventHandler) -> { if (isAutoShowAndHide()) { hide(); } if (menuItem.getOnAction() != null) { menuItem.getOnAction().handle(null); } }); } final private MenuItem menuItem;
menuItem.getOnAction().handle(new ActionEvent());
menuItem.getOnAction().handle(new ActionEvent());
public Node apply(MultiSelect<E> multiSelect, E item) { SplitMenuButton button = new SplitMenuButton(); button.setText(multiSelect.getConverter().toString(item)); MenuItem remove = new MenuItem(String.format("Remove %s", item)); remove.setOnAction(event -> { int index = multiSelect.getChildrenUnmodifiable().indexOf(button); multiSelect.getItems().remove(item); multiSelect.getChildrenUnmodifiable().get(index).requestFocus(); }); button.getItems().add(remove); button.addEventFilter(KeyEvent.KEY_PRESSED, event -> { if (event.getCode() == KeyCode.BACK_SPACE) remove.getOnAction().handle(null); }); return button; } }
private static void unconfigure(final MenuItem menuItem) { if (menuItem == null || !(menuItem.getOnAction() instanceof Action)) { return; } Action action = (Action) menuItem.getOnAction(); menuItem.styleProperty().unbind(); menuItem.textProperty().unbind(); menuItem.disableProperty().unbind(); menuItem.acceleratorProperty().unbind(); menuItem.graphicProperty().unbind(); action.getProperties().removeListener(new MenuItemPropertiesMapChangeListener<>(menuItem, action)); if (menuItem instanceof RadioMenuItem) { ((RadioMenuItem) menuItem).selectedProperty().unbindBidirectional(action.selectedProperty()); } else if (menuItem instanceof CheckMenuItem) { ((CheckMenuItem) menuItem).selectedProperty().unbindBidirectional(action.selectedProperty()); } menuItem.setOnAction(null); }