Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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);`
like image 350
Strom Avatar asked Jan 29 '26 02:01

Strom


1 Answers

You can consume the event that signifies a request has been made for a context menu:

CombatFeedback.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
like image 181
James_D Avatar answered Jan 31 '26 15:01

James_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!