Muhamet Aljobairi
Muhamet Aljobairi

Reputation: 1638

JavaFx : Event Filter on Tab (Tab Pane)

I'm working on Tab Pane on JavaFx, my problem is that i can't handle any KeyEvent inside the tab, such as F5 press or any key on the keyboard, also the function is working on any element inside the Tab like TextField, my goal is to handle any event inside the Tab not elements.

This is my code that i tested it

tab.getContent().addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {

        @Override
        public void handle(KeyEvent event) {
            System.out.println("Filtering out event " + event.getCode());
            event.consume();
        }
    });

Upvotes: 1

Views: 832

Answers (1)

Ugurcan Yildirim
Ugurcan Yildirim

Reputation: 6132

As far as I understand from another Stack Overflow post, layouts (TabPane in your case) do not respond to KeyEvents. So, the solution suggested and also worked for that post is adding the event filter to the scene. If you don't prefer doing that, set TabPane focusable and try your way again.

Upvotes: 1

Related Questions