2

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);`
Strom
  • 93
  • 1
  • 10
  • possible duplicate of http://stackoverflow.com/questions/13562712/how-to-disable-the-default-context-menu-on-a-text-field – Rahul Singh Mar 30 '17 at 18:04
  • 1
    My impression was that that question dealt with a much earlier version of the JavaFX toolkit because of the double screen problem. I assumed the more recent JavaFX would be able to offer a less convoluted and more straightforward solution. Sorry if that isn't the case though. – Strom Mar 30 '17 at 19:34

1 Answers1

13

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

CombatFeedback.addEventFilter(ContextMenuEvent.CONTEXT_MENU_REQUESTED, Event::consume);
James_D
  • 201,275
  • 16
  • 291
  • 322