JavaFX: Focusing textfield programmatically

后端 未结 2 815
不知归路
不知归路 2021-01-03 22:44

I wrote an application with JavaFX which will only be usable with keyboard\'s arrows. So I prevented MouseEvent on Scene\'s stage, and I \"listen\" to KeyEvents. I also swit

2条回答
  •  礼貌的吻别
    2021-01-03 23:04

    set the .requestFocus(); on initialize method to fire on .fxml file loading controller

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    /* the field defined on .fxml document  
    @FXML
    private TextField txtYear;
    */
    txtYear.requestFocus();
    }
    

提交回复
热议问题