public class Main extends Application { @Override public void start(final Stage primaryStage) throws Exception { final Alert alert = new Alert(Alert.AlertType.INFORMATION); primaryStage.setScene(new Scene(new Group(), 300, 300, Color.BLACK)); alert.initOwner(primaryStage); alert.showAndWait(); } public static void main(final String... args) { launch(args); } }
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { // consume event event.consume(); // show close dialog Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Close Confirmation"); alert.setHeaderText("Do you really want to quit?"); alert.initOwner( primaryStage); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.OK){ Platform.exit(); } } });
private void createWarning() { Alert connectionLostAlert = new Alert(AlertType.WARNING); connectionLostAlert.setHeaderText("Lost connection"); connectionLostAlert.initOwner(mainWindow); connectionLostAlert.showAndWait(); } }
JColorChooser colorChooser = new JColorChooser(java.awt.Color.CYAN); SwingNode colorChooserNode = new SwingNode(); colorChooserNode.setContent(colorChooser); Alert dialog = new Alert(Alert.AlertType.NONE); // Guarantees dialog will be above (and will block input to) mainStage. dialog.initOwner(mainStage); dialog.setTitle("Select a color"); dialog.getDialogPane().setContent(colorChooserNode); dialog.getDialogPane().getButtonTypes().setAll( ButtonType.OK, ButtonType.CANCEL); Optional<ButtonType> response = dialog.showAndWait(); if (response.filter(r -> r == ButtonType.OK).isPresent()) { int rgb = colorChooser.getColor().getRGB(); String hex = String.format("#%06x", rgb & 0xffffff); Text.setText(hex); ShortcutButton.setBackground(new Background( new BackgroundFill(Color.valueOf(hex), null, null))); } else { System.out.println("User canceled"); }
private void deleteSelected(Window owner) { if (uniformDesign.isAskBeforeDelete()){ Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.initOwner(owner); alert.setTitle(uniformDesign.getText(deleteConfirmationTitle)); alert.setHeaderText(uniformDesign.getText(deleteConfirmationHeader)); alert.setContentText(uniformDesign.getText(deleteConfirmationContent)); Optional<ButtonType> result = alert.showAndWait(); if (result.isPresent()){ if (result.get() != ButtonType.OK){ return; } } } final List<T> selectedItems = new ArrayList<>(tableView.getSelectionModel().getSelectedItems()); selectedItems.forEach(t -> deleter.accept(t,referenceListAttribute)); }
if (textField.getText().trim().isEmpty()) { Alert alert2 = new Alert(AlertType.ERROR, "Please enter a value", ButtonType.OK); alert2.initOwner(dialog2.getDialogPane().getScene().getWindow()); alert2.showAndWait();
@Override public void showMessageDialog(final Window parent, final Alert.AlertType alertType, final String titleKey, final String messageKey, final Object... arguments) { final String message = fxResources.getString(messageKey, arguments); final Alert alert = new Alert(alertType, message); alert.initOwner(parent); alert.setTitle(fxResources.getString(titleKey)); alert.setHeaderText(null); alert.showAndWait(); }
/** * show the given alert * * @param stage * @param title * @param headerText * @param content * @param alertType */ private static void doshowAlert(Stage stage, String title, String headerText, String content, AlertType alertType) { Alert alert = new Alert(alertType); alert.initOwner(stage); alert.setTitle(title); alert.setHeaderText(headerText); alert.setContentText(content); alert.showAndWait(); }
@Override public Optional<ButtonType> showConfirmationDialog(final Window parent, final String titleKey, final String messageKey, final ButtonType... buttonTypes) { final Alert alert = new Alert(Alert.AlertType.CONFIRMATION, fxResources.getString(messageKey)); alert.initOwner(parent); alert.setTitle(fxResources.getString(titleKey)); alert.setHeaderText(null); // add custom button types if specified if (buttonTypes.length > 0) { alert.getButtonTypes().setAll(buttonTypes); } return alert.showAndWait(); }
alert.initOwner(stage); alert.getDialogPane().setContentText("Some text");
alert.initOwner(stage); alert.getDialogPane().setContentText("Some text");
+ item.toLowerCase() + "?"); alertBox.initOwner(owner); /* *** */ alertBox.showAndWait(); if (alertBox.getResult() == ButtonType.OK) {
String headerText, Throwable th, Linker linker) { Alert alert = new Alert(AlertType.ERROR); alert.initOwner(stage); alert.setTitle(title); alert.setHeaderText(headerText);