How to create and show common dialog (Error, Warning, Confirmation) in JavaFX 2.0?

Anton picture Anton · Nov 29, 2011 · Viewed 163.4k times · Source

How do I create and show common dialogs (Error, Warning, Confirmation) in JavaFX 2.0? I can't find any "standard" classes like Dialog, DialogBox, Message or something.

Answer

Ali Cheaito picture Ali Cheaito · Mar 5, 2015

Recently released JDK 1.8.0_40 added support for JavaFX dialogs, alerts, etc. For example, to show a confirmation dialog, one would use the Alert class:

Alert alert = new Alert(AlertType.CONFIRMATION, "Delete " + selection + " ?", ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);
alert.showAndWait();

if (alert.getResult() == ButtonType.YES) {
    //do stuff
}

Here's a list of added classes in this release: