当用户选择关闭按钮时如何阻止阶段关闭?
How to stop a stage from closing when user selects close button?
我可以添加这段代码来挂钩舞台关闭事件:
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!
}
});
但是如何阻止舞台关闭?
我参考this评论:
Platform.setImplicitExit(false);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
event.consume();
}
});
我可以添加这段代码来挂钩舞台关闭事件:
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!
}
});
但是如何阻止舞台关闭?
我参考this评论:
Platform.setImplicitExit(false);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
event.consume();
}
});