如何点击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
}
});