I have an undecorated stage in a JavaFX Application. In order to minimize it I need a minimize button. I created my layout in an fxml document
which has a minimize button
, but when I try to minimize using the action listener
for this button located inside the controller using stage.setIconified(true)
, it cannot find stage.
How can I find a reference to the stage in the controller class?
You can try :
button.setOnAction(e -> {
((Stage)((Button)e.getSource()).getScene().getWindow()).setIconified(true);
});
Solution number 1 is what ItachiUchiha posted.
Solution number 2 is just creating a setter-method in the controller and give the controller the stage itself.
Use this Stage stage = (Stage) minimize.getScene().getWindow(); stage.setIconified(true); // minimize can be any element in that scene
Stage stage = (Stage) minimize.getScene().getWindow(); stage.setIconified(true); // minimize can be any element in that scene
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.