Advertisement
Guest User

Prevent dialog from closing

a guest
Jun 13th, 2015
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.event.EventHandler;
  3. import javafx.scene.control.ButtonType;
  4. import javafx.scene.control.Dialog;
  5. import javafx.scene.control.DialogEvent;
  6. import javafx.stage.Stage;
  7.  
  8. public class DialogTest extends Application {
  9.    
  10.     public static void main(String[] args) {
  11.         launch(args);
  12.     }
  13.  
  14.     @Override
  15.     public void start(Stage primaryStage) throws Exception {
  16.         Dialog<Void> dialog = new Dialog<>();
  17.         dialog.setOnCloseRequest(new EventHandler<DialogEvent>() {
  18.             @Override
  19.             public void handle(DialogEvent event) {
  20.                 event.consume();
  21.                 System.out.println("Consumed event: " + event.isConsumed());
  22.             }
  23.         });
  24.         dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
  25.         dialog.show();
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement