You could follow this code and modify to suit your needs:
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Warning");
// Show the alert and wait for the user's response
alert.showAndWait().ifPresent(response -> {
if (response == ButtonType.OK) {
// User clicked OK, navigate away from the edit screen
} else {
// User clicked Cancel or closed the alert, do nothing
}
});
I hope this helps.