How to call functions on the stage in JavaFX's controller file

后端 未结 6 1836
孤独总比滥情好
孤独总比滥情好 2021-01-02 05:08

I am using javafx along with fxml, so I use the controller for the real coding. I need to do a few operations on the stage, such as getting

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 05:34

    With *.FXML files and Controllers and not with Main or Events , use this :

    @FXML private Stage stage;
    stage = (Stage) elemen.getScene().getWindow();
    

    element, can be any control or element in you FXML, in my case is an AnchorPane:

    @FXML  private AnchorPane element;
    

提交回复
热议问题