Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX - Button to minimize the stage

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?

like image 444
Josh Beaver Avatar asked Dec 25 '22 21:12

Josh Beaver


1 Answers

You can try :

button.setOnAction(e -> {
    ((Stage)((Button)e.getSource()).getScene().getWindow()).setIconified(true);
});
like image 186
ItachiUchiha Avatar answered Dec 27 '22 10:12

ItachiUchiha