所以仍然有点弄清楚JavaFX,我能够禁用在文本框中输入文本,但我不确定如何在右键单击时阻止上下文菜单出现。是否有人知道如何防止右键单击时弹出默认上下文菜单? `
//CombatFeedback is scrollable textbox to update user on what's happening.
TextArea CombatFeedback= new TextArea("Text.");
CombatFeedback.setPrefColumnCount(20);
CombatFeedback.setPrefRowCount(5);
CombatFeedback.setWrapText(true);
CombatFeedback.setStyle("-fx-font: 20 arial");
CombatFeedback.setEditable(false);
ScrollPane scrollerCombat = new ScrollPane(CombatFeedback);`
答案 0 :(得分:6)
您可以使用表示已为上下文菜单发出请求的事件:
CombatFeedback.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);