Search code examples
javajavafxfocus

Javafx . How to get next Element non Focus Lost


I have a focus-listener on a TextField and would like to know which will the next element that gains the focus. (And maybe change it under special circumstances)

Any Idea?

class Data extends TextField {
    public Data(int i) {
        focusedProperty().addListener((o, ov, nv) -> {
            if(!nv){               
              // Get Next Focusserd Item ...
            } 
        });
    }
}

Solution

  • Get the value of the focusOwner property from the scene.

    Node focusOwner = getScene().getFocusOwner();
    

    requestFocus can be used to get the focus to some other node, e.g.

    if (focusOwner != otherNode) {
        thirdNode.requestFocus();
    }