本文介绍了如何在JavaFX中禁用Context Menu?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以仍然有点弄清楚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. 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);`
推荐答案
您可以使用表示已为上下文菜单发出请求的事件:
You can consume the event that signifies a request has been made for a context menu:
CombatFeedback.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
这篇关于如何在JavaFX中禁用Context Menu?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!