Reputation: 145
When I press the red close button, I want the window not to close on JavaFX.
Any suggestions?
Upvotes: 2
Views: 647
Reputation: 209603
From the Javadocs for Window.setOnCloseRequest()
:
Called when there is an external request to close this Window. The installed event handler can prevent window closing by consuming the received event.
So all you need is
stage.setOnCloseRequest(Event::consume);
or, if you are going to perform other actions as well:
stage.setOnCloseRequest(event -> {
// do some stuff...
event.consume();
});
Upvotes: 8