0

I can add this code to hook into the stage close event:

stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
    public void handle(WindowEvent we) {
        System.out.println("Stage is closing");
        // but wait! I don't want it to close!
    }
});  

but how do I stop the stage from closing?

nicomp
  • 4,344
  • 4
  • 27
  • 60

1 Answers1

1

I refer to this comment:

Platform.setImplicitExit(false);

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
    @Override
    public void handle(WindowEvent event) {
        event.consume();
    }
});
SilverMonkey
  • 1,003
  • 7
  • 16