Alert alert = new Alert(AlertType.CONFIRMATION, "Delete " + selection + " ?", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); alert.showAndWait(); if (alert.getResult() == ButtonType.YES) { //do stuff }
import javafx.scene.control.Alert import javafx.scene.control.Alert.AlertType; import javafx.application.Platform; public class ClassNameHere { public static void infoBox(String infoMessage, String titleBar) { /* By specifying a null headerMessage String, we cause the dialog to not have a header */ infoBox(infoMessage, titleBar, null); } public static void infoBox(String infoMessage, String titleBar, String headerMessage) { Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle(titleBar); alert.setHeaderText(headerMessage); alert.setContentText(infoMessage); alert.showAndWait(); } }
private void showLicensePopup() { Alert licenseAlert = new Alert(AlertType.INFORMATION); licenseAlert.setWidth(500); licenseAlert.setHeaderText("License"); ScrollPane scroll = new ScrollPane(); try { scroll.setContent(new TextArea(IOUtils.toString(getClass().getResourceAsStream("LICENSE"), StandardCharsets.UTF_8))); } catch (IOException e) { e.printStackTrace(); } licenseAlert.getDialogPane().setContent(scroll); licenseAlert.showAndWait(); }
@Override public Optional<ButtonType> showWarning(String title, String message) { final Alert alert = new Alert(Alert.AlertType.CONFIRMATION); final Scene scene = alert.getDialogPane().getScene(); BrandUtil.applyBrand(injector, stage, scene); alert.setTitle("Confirmation"); alert.setHeaderText(title); alert.setContentText(message); alert.setGraphic(FontAwesome.EXCLAMATION_TRIANGLE.view()); return alert.showAndWait(); }
public boolean showConfirmDialog(String title, String header, String content, AlertType alertType) { final Alert alert = new Alert(alertType); alert.setTitle(title); alert.setHeaderText(header); alert.setContentText(content); alert.getButtonTypes().clear(); alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); //Deactivate Defaultbehavior for yes-Button: Button yesButton = (Button) alert.getDialogPane().lookupButton( ButtonType.YES ); yesButton.setDefaultButton( false ); //Activate Defaultbehavior for no-Button: Button noButton = (Button) alert.getDialogPane().lookupButton( ButtonType.NO ); noButton.setDefaultButton( true ); final Optional<ButtonType> result = alert.showAndWait(); return result.get() == ButtonType.YES; }
Alert alert = new Alert(AlertType.WARNING, "File already exists. Do you want to override?", ButtonType.YES, ButtonType.NO); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.YES){ // ... user chose YES } else { // ... user chose NO or closed the dialog }
Alert alert = createAlertWithOptOut(AlertType.CONFIRMATION, "Exit", null, "Are you sure you wish to exit?", "Do not ask again", param -> { prefs.put(KEY_AUTO_EXIT, param ? "Always" : "Never"); return null; }, ButtonType.YES, ButtonType.NO); if (alert.showAndWait().filter(t -> t == ButtonType.YES).isPresent()) { System.exit(); }
okButton.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setContentText("You pressed OK!"); alert.showAndWait(); } });
Exception e = new Exception("An exception!!!!!!!!!!!!!!!!!"); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText("An exception occurred!"); alert.getDialogPane().setExpandableContent(new ScrollPane(new TextArea(sw.toString()))); alert.showAndWait();
Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Message Here..."); alert.setHeaderText("Look, an Information Dialog"); alert.setContentText("I have a great message for you!"); alert.showAndWait().ifPresent(rs -> { if (rs == ButtonType.OK) { System.out.println("Pressed OK."); } });
private void setAlert(final String title, final String header, final String content) { final Alert alert = new Alert(AlertType.WARNING); alert.setTitle(RESOURCES.getString(title)); alert.setHeaderText(RESOURCES.getString(header)); alert.setContentText(RESOURCES.getString(content)); alert.showAndWait(); }
Alert a = new Alert(AlertType.ERROR); a.setTitle("Title of alert"); a.initStyle(StageStyle.UNDECORATED); a.setContentText("details of message"); a.showAndWait();
Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle("Confirmation Dialog"); alert.setHeaderText("Warning !"); alert.setContentText("Are you sure you want to perform this action ?"); Optional<ButtonType> result = alert.showAndWait(); if (result.get() == ButtonType.OK) { // delete user }
private void createWarning() { Alert connectionLostAlert = new Alert(AlertType.WARNING); connectionLostAlert.setHeaderText("Lost connection"); connectionLostAlert.initOwner(mainWindow); connectionLostAlert.showAndWait(); } }
Alert dialog = new Alert(Alert.AlertType.ERROR); dialog.setHeaderText("Connection Failed"); dialog.setContentText(this.getException().getMessage()); //FIXME: Remove after release 8u40 dialog.setResizable(true); dialog.getDialogPane().setPrefSize(480, 320); dialog.showAndWait();
public static void showDialogError(String message) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle(GSE_ERROR); alert.setResizable(true); alert.setContentText(message); alert.showAndWait(); }
/** * Shows an info dialog. * * @param message the message */ public void showInfoDialog(String message) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle(FxFxBundle.getString("INFORMATION")); setAlertMessage(alert, message); alert.showAndWait(); }
public static void showWarning(String title, String message) { final Alert alert = new Alert(Alert.AlertType.WARNING); alert.initStyle(StageStyle.UTILITY); alert.setTitle("Warning"); alert.setHeaderText(title); alert.setContentText(message); alert.showAndWait(); }
public static void showInformation(String title, String message) { final Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.initStyle(StageStyle.UNDECORATED); alert.setTitle("Information"); alert.setHeaderText(title); alert.setContentText(message); alert.showAndWait(); }