remove default focus from TextField JavaFX

Yashar picture Yashar · Mar 14, 2015 · Viewed 15.9k times · Source

I have designed some TextField in a form by SceneBuilder, when I run the code, one of the TextFields has been clicked by default, I want when I run the code, none of the TextFields get selected by default and user select a TextFiled.

UPDATE: As you see in this image I want to make the first field like other two field when code runs(no curser in field)

How can I do this?

Answer

dermoritz picture dermoritz · Jul 14, 2016

In my case the accepted answer is not working. But this worked:

i requested focus for parent wrapped in runLater.

@FXML
public void initialize() {

    //unfocus pathField
    Platform.runLater( () -> root.requestFocus() );
}

Direct call of requestFocuss does not work.