我正在尝试创建当我点击鼠标右键时显示的上下文菜单 但它看起来我只能将上下文菜单添加到控件中 这是我的代码
MenuItem copy = new MenuItem("Copy");
MenuItem paste = new MenuItem("Paste");
MenuItem cut = new MenuItem("Cut");
edit.getItems().addAll(copy,paste,cut);
ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().addAll(copy,cut,paste);
pane.setContextMenu(contextMenu);
pane.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
if (event.isSecondaryButtonDown()) {
System.out.println("asasasa");
contextMenu.show(pane, event.getScreenX(), event.getScreenY());
} else
contextMenu.hide();
});