RequestFocus in TextField doesn't work
问题 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 control. 回答1: At the time of initialize() controls are not yet ready to handle focus. You can try next trick: @Override public void initialize(URL url, ResourceBundle rb) { Platform.runLater(new Runnable() { @Override public void run() { tf.requestFocus(); } }); } For tricky complex applications (like Pavel_K has in the comments) you may