Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setDefaultCloseOperation() in JavaFX

Is there a way to set a custom closeoperation in JavaFX. I know this one from swing and couldn't find it for JavaFX. If you close your window here by pressing the [X], it will close automatically.

like image 594
codepleb Avatar asked Dec 25 '22 22:12

codepleb


1 Answers

You can use the onCloseRequest property:

stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
    @Override public void handle(WindowEvent t) {
        System.out.println("CLOSING");
    }
});

Note that if you call Platform.exit() in your code, this won't work.

like image 124
assylias Avatar answered Jan 11 '23 02:01

assylias