Class Alert

  • All Implemented Interfaces:
    EventTarget

    public class Alert
    extends Dialog<ButtonType>

    The Alert class provides a number of pre-built dialogs made to be used in a common set of use cases.

    The type of Alert is set by passing in an Alert.AlertType instance. This will dictate which buttons are displayed as well as a graphic illustrating the intention of the dialog.

    All Alerts have an optional content text as well as an optional title, are modal and blocking. "Modal" means that the user is prevented from interacting with the rest of the application while the Alert is showing and "blocking" means the call to Dialog.showAndWait() blocks code execution until the Alert is closed, this means the developer can show the Alert and interact with the result right after the method Dialog.showAndWait() returns, which typically simplifies the code.

    The Alert types are:

    • CONFIRMATION
    • ERROR
    • WARNING
    • INFORMATION
    • NONE
    To instantiate and show an Alert you can use code as the following:
     
     Alert alert = new Alert(AlertType.CONFIRMATION, "Some question to accept or reject");
     alert.showAndWait();
     
     

    Screenshot of Confirmation Alert

    Screenshot of Confirmation Alert

    Since:
    2.0.0
    See Also:
    Dialog