关闭应用javafx什么都不做

时间:2018-05-31 10:33:55

标签: java javafx application-close

如何点击X?

时确保窗口没有关闭
stage.setOnCloseRequest((WindowEvent t) -> {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Attention");
    alert.setContentText("Would you close the application?");
    ButtonType buttonTypeOne = new ButtonType("Yes");
    ButtonType buttonTypeTwo = new ButtonType("No");
    alert.getButtonTypes().setAll(buttonTypeOne, buttonTypeTwo);
    Optional<ButtonType> result = alert.showAndWait();

    if (result.get() == buttonTypeOne) {
        stage.close();
    } else if (result.get() == buttonTypeOne) {
        // NOT CLOSE
    }
});

0 个答案:

没有答案