I use JavaFX 2.1 and I created GUI using FXML, in the controller of this GUI I added myTextField.requestFocus();
.
But I always get the focus in the other co
I ran into the same problem using JavaFX 11 and solved it in a similar way that nickthecoder proposed.
ChangeListener sceneListener = new ChangeListener() {
@Override
public void changed(ObservableValue extends Scene> observable, Scene oldValue, Scene newValue) {
if (newValue != null) {
editInput.requestFocus();
editInput.sceneProperty().removeListener(this);
}
}
};
editInput.sceneProperty().addListener(sceneListener);
Basicly just add a listener to the sceneProperty of the node and in that listener request focus once the scene is set. I also wrote it in such a way that the listener will be removed after it is invoked.