public class Alert extends Dialog
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:
Alert alert = new Alert(AlertType.CONFIRMATION, "Some question to accept or reject");
alert.showAndWait();
Dialog
Type | Property and Description |
---|---|
javafx.beans.property.ObjectProperty<javafx.scene.control.Alert.AlertType> |
alertType
The type of Alert, one of the
Alert.AlertType
possible types |
Constructor and Description |
---|
Alert(javafx.scene.control.Alert.AlertType alertType)
Creates an empty Alert with the given type.
|
Alert(javafx.scene.control.Alert.AlertType type,
java.lang.String contentText)
Creates an Alert with the given type and content text
|
Modifier and Type | Method and Description |
---|---|
javafx.beans.property.ObjectProperty<javafx.scene.control.Alert.AlertType> |
alertTypeProperty()
The type of Alert, one of the
Alert.AlertType
possible types |
javafx.scene.control.Alert.AlertType |
getAlertType()
Gets the value of the property alertType.
|
void |
setAlertType(javafx.scene.control.Alert.AlertType value)
Sets the value of the property alertType.
|
autoHideProperty, buildEventDispatchChain, contentProperty, contentTextProperty, getButtons, getContent, getContentText, getGraphic, getId, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getTitle, getTitleText, graphicProperty, hide, idProperty, isAutoHide, isFullscreen, isShowing, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, setAutoHide, setContent, setContentText, setGraphic, setId, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setResult, setTitle, setTitleText, showAndWait, showingProperty, titleProperty, titleTextProperty
public final javafx.beans.property.ObjectProperty<javafx.scene.control.Alert.AlertType> alertTypeProperty
Alert.AlertType
possible typesgetAlertType()
,
#setAlertType(AlertType)
public Alert(javafx.scene.control.Alert.AlertType alertType)
alertType
- The type of alertpublic Alert(javafx.scene.control.Alert.AlertType type, java.lang.String contentText)
type
- the type of this AlertcontentText
- the text content of this Alertpublic final javafx.beans.property.ObjectProperty<javafx.scene.control.Alert.AlertType> alertTypeProperty()
Alert.AlertType
possible typesgetAlertType()
,
#setAlertType(AlertType)
public final javafx.scene.control.Alert.AlertType getAlertType()
Alert.AlertType
possible typespublic final void setAlertType(javafx.scene.control.Alert.AlertType value)
Alert.AlertType
possible types