×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Richard McDonald
Added: Aug 16, 2016 12:41 PM
Views: 62
Tags: dialog javafx
Uses lambda expression to process result
  1. Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
  2. alert.setTitle("Current project is modified");
  3. alert.setContentText("Save?");
  4. ButtonType okButton = new ButtonType("Yes", ButtonBar.ButtonData.YES);
  5. ButtonType noButton = new ButtonType("Yes", ButtonBar.ButtonData.NO);
  6. ButtonType cancelButton = new ButtonType("Yes", ButtonBar.ButtonData.CANCEL_CLOSE);
  7. alert.getButtonTypes().setAll(okButton, noButton, cancelButton);
  8. alert.showAndWait().ifPresent(type -> {
  9.         if (type == ButtonType.OK) {
  10.         } else if (type == ButtonType.NO) {
  11.         } else {
  12.         }
  13. });
  14.