Canvas and Keyboard events
Bryan Buchanan
bryanb at webbtide.com
Mon Feb 29 22:19:02 UTC 2016
I have this layout:
BorderPane with a MenuBar (top) and TabPane (center)
I have two initial tabs. Selecting some menu option will create a new tab.
One of the menu options creates a drawing surface, which is made up of a
StackPane with a Canvas. The canvas has FocusTraversable set to true and
has keyboard event handlers:
canvas.setFocusTraversable(true);
canvas.setOnKeyPressed((KeyEvent e) -> handleHotKeys(e));
canvas.setOnKeyTyped((KeyEvent e) -> handleChars(e));
The canvas responds to keyboards events - I can get "a", "b", "c" etc, DEL,
INS, END and other keys I'm interested in. However, when I press "left
arrow" or "right arrow", the MenuBar gets focus. If I then click in the
canvas, the Tab control gets focus. If I keep pressing an arrow key, the
tabs cycle though, until I get back to the tab with the canvas, then the
arrow events are sent to the canvas, and it works like it should. I don't
understand why the arrow key events don't go first to the canvas.
Any clues appreciated.
More information about the openjfx-dev
mailing list