当用户选择关闭按钮时如何停止关闭阶段?

时间:2017-06-04 11:58:17

标签: java javafx scenebuilder

我可以添加此代码以挂钩舞台关闭事件:

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!
    }
});  

但是如何阻止舞台关闭?

1 个答案:

答案 0 :(得分:1)

我参考this评论:

Platform.setImplicitExit(false);

primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
    @Override
    public void handle(WindowEvent event) {
        event.consume();
    }
});