codepleb
codepleb

Reputation: 10571

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.

Upvotes: 4

Views: 5377

Answers (1)

assylias
assylias

Reputation: 328745

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.

Upvotes: 10

Related Questions