我可以添加此代码以挂钩舞台关闭事件:
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!
}
});
但是如何阻止舞台关闭?
答案 0 :(得分:1)
我参考this评论:
Platform.setImplicitExit(false);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
event.consume();
}
});