do nothing on close application javafx

126 views Asked by At

how can I make sure that the window does not close when I click on the 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

There are 0 answers