public static void main(String[] args){ launch(args); } private boolean modalWasShowing = false; @Override public void start(Stage primaryStage) { final Alert d = new Alert(Alert.AlertType.ERROR); d.initModality(Modality.WINDOW_MODAL); Button btn = new Button(); btn.setText("Say 'Hello World'"); btn.addEventFilter(KeyEvent.KEY_RELEASED, event -> { if(modalWasShowing){ modalWasShowing=false; return; } if ((event.getCode() == KeyCode.ENTER || event.getCode() == KeyCode.TAB)) { modalWasShowing = true; d.showAndWait(); } }); Scene scene = new Scene(new StackPane(btn), 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); }
alert.setContentText( "Choose your option." ); ButtonType buttonTypeOne = new ButtonType( "Yes" ); alert.initModality( Modality.NONE ); ButtonType buttonTypeCancel = new ButtonType( "No", ButtonBar.ButtonData.CANCEL_CLOSE ); alert.getButtonTypes().setAll( buttonTypeOne, buttonTypeCancel );
Alert alert = new Alert(AlertType.WARNING); alert.initModality(Modality.APPLICATION_MODAL); alert.initOwner(stage); alert.getDialogPane().setContentText("Some text");
Alert alert = new Alert(AlertType.WARNING); alert.initModality(Modality.APPLICATION_MODAL); alert.initOwner(stage); alert.getDialogPane().setContentText("Some text");
d.initModality(Modality.WINDOW_MODAL);
alertBox.setContentText("Are you sure you want to delete this " + item.toLowerCase() + "?"); alertBox.initModality(Modality.APPLICATION_MODAL); /* *** */
alertOut.setHeaderText("Look, a Confirmation Dialog"); alertOut.setContentText("Are you ok with this?"); alertOut.initModality(Modality.NONE); ((Stage)alertOut.getDialogPane().getScene().getWindow()).setOpacity(0);