简体   繁体   English

如何在JavaFX中禁用上下文菜单?

[英]How to disable Context Menu in JavaFX?

So still kind of figuring out JavaFX, I was able to disable entering text in the textbox but I am not sure how to prevent the context menu from coming up when right clicked. 因此,仍然可以弄清楚JavaFX,我可以禁止在文本框中输入文本,但是我不确定如何右键单击时不显示上下文菜单。 Is anybody aware of how to prevent the default context menu from popping up when right clicked? 有谁知道如何防止右键单击时弹出默认上下文菜单? ` `

//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);`

您可以使用表示已请求上下文菜单的事件:

CombatFeedback.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM