JavaFX: How to change the focus traversal policy?

后端 未结 10 1908
广开言路
广开言路 2020-11-30 04:34

Is it possible in JavaFX to change the focus traversal policy, like in AWT?

Because the traversal order for two of my HBoxes is wrong.

10条回答
  •  情书的邮戳
    2020-11-30 05:33

    We're using JavaFX event filters for this, e.g.:

    cancelButton.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler() {
        @Override
        public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.TAB && event.isShiftDown()) {
                event.consume();
                getDetailsPane().requestFocus();
            }
        }
    });
    

    The event.consume() suppresses the default focus traversal, which otherwise causes trouble when calling requestFocus().

提交回复
热议问题