setDefaultCloseOperation() in JavaFX


Question

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.

1
3
8/15/2013 1:36:01 PM

Accepted Answer

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.

9
8/15/2013 3:15:08 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon