1

I'd like to disable focus system in a JavaFX application. That means no focus traversal, no control could receive focus, so it would never have corresponding graphic decoration and would never receive keyboard events. All keyboard events should be caught and processed by the root node (or stage).

What should I extend/rewrite to disable focus system?

ayvango
  • 5,867
  • 3
  • 34
  • 73

1 Answers1

-1

To process all keyboard events in the root node, do

root.addEventFilter(KeyEvent.ANY, e -> {
    // handle keyboard event...
    e.consume();
});
James_D
  • 201,275
  • 16
  • 291
  • 322
  • 1
    Looks like hack. Something like redefining Scene.keyHandler and Scene.requestFocus seems more straitforward – ayvango Jul 04 '15 at 14:10
  • I don't think of this as a hack; it's exactly the way the API is intended to be used. – James_D Jul 04 '15 at 14:54