JavaFX: How to change the focus traversal policy?

后端 未结 10 1902
广开言路
广开言路 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:16

    I used Eventfilter as solution in combination with referencing the field ID's, so all you have to do is name the fields like (field1,field2,field3,field4) so you can place the fields where u want:

    mainScene.addEventFilter(KeyEvent.KEY_PRESSED, (event) -> {
            if(event.getCode().equals(KeyCode.TAB)){
                event.consume();
                final Node node =  mainScene.lookup("#field"+focusNumber);
                if(node!=null){
                    node.requestFocus();
                }
                focusNumber ++;
                if(focusNumber>11){
                  focusNumber=1;
                }
            }
        }); 
    

提交回复
热议问题