T
- The return type of the showAndWait()
method.@IDProperty(value="id")
public class Dialog<T>
extends java.lang.Object
implements javafx.event.EventTarget
A Dialog is composed of a graphic, a title, a content node and a collection of buttons.
The Dialog class is the Glisten API for showing dialogs that are modal and blocking. "Modal" means that the user
is prevented from interacting with the rest of the application while the Dialog is showing and "blocking" means
the call to showAndWait()
blocks code execution until the Dialog is closed, this means the developer
can show the Dialog and interact with the result right after the method showAndWait()
returns, which
typically simplifies the code.
The Dialog class is a powerful class. It is the base class for any Dialog based control, but it can also be used to create simple Dialogs with a text title, a text content and one or two buttons for the user to interact with. The example below creates and shows such a Dialog:
Dialog dialog = new Dialog();
dialog.setTitle(new Label("This is a regular dialog"));
dialog.setContent(new Label("Just a regular dialog, plain and simple");
Button okButton = new Button("OK");
okButton.setOnAction(e -> {
dialog.hide();
});
dialog.getButtons().add(okButton);
dialog.showAndWait();
You can also create fullscreen dialogs by passing in true to the Dialog constructor. Fullscreen dialogs are
essentially Views
and are used for example when the dialog includes components (like pickers or form fields)
that require a keyboard.
Fullscreen dialog's controls are inside the AppBar including a close button (Nav Icon), the title and the buttons list (Action Icons). The content is inserted in the center of the View.
The following example shows a fullscreen dialog. When the dialog closes a confirmation dialog is displayed, to ask the user whether he wants to 'discard' changes or keep them. If the user presses 'keep editing' the close request event is consumed and so the dialog doesn't close, otherwise we let the event go through (this is a common workflow in Material Design: https://www.google.com/design/spec/components/dialogs.html#dialogs-full-screen-dialogs).
Dialog dialog = new Dialog(true);
dialog.setTitleText("");
dialog.setContent(new Label("Some dialog content..."));
Button saveButton = new Button("SAVE");
dialog.getButtons().addAll(saveButton);
dialog.setOnCloseRequest(closeRequestEvent -> {
Dialog areYouSureDialog = new Dialog(false);
areYouSureDialog.setContent(new Label("Are you sure you want to discard all changes?"));
Button yesButton = new Button("DISCARD");
Button noButton = new Button("KEEP EDITING");
yesButton.setOnAction(event2 -> {
areYouSureDialog.hide();
});
noButton.setOnAction(event2 -> {
closeRequestEvent.consume();
areYouSureDialog.hide();
});
areYouSureDialog.getButtons().addAll(yesButton, noButton);
areYouSureDialog.showAndWait();
});
dialog.showAndWait();
Alert
,
TimePicker
,
DatePicker
Type | Property and Description |
---|---|
javafx.beans.property.BooleanProperty |
autoHide
This property indicates whether the Dialog should close if a mouse/finger is pressed/tapped
outside of the Dialog.
|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
content
The content of the Dialog.
|
javafx.beans.property.StringProperty |
contentText
The String content of the dialog, setting this property with a non null value will result
in the content being a
Label with the value of this property as the text. |
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
graphic
The graphic to be displayed in this Dialog.
|
javafx.beans.property.StringProperty |
id
The id of this
Dialog . |
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onCloseRequest
Called when there is an external request to close this Dialog.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onHidden
Called just after the Dialog has been hidden.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onHiding
Called just prior to the Dialog being hidden.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onShowing
Called just prior to the Dialog being shown.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onShown
Called just after the Dialog is shown.
|
javafx.beans.property.ReadOnlyBooleanProperty |
showing
Represents whether the Dialog instance is currently showing or not.
|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
title
The title of the Dialog.
|
javafx.beans.property.StringProperty |
titleText
The String title of the dialog, setting this property with a non null value will result
in the title being a
Label with the value of this property as the text. |
Modifier and Type | Field and Description |
---|---|
protected javafx.scene.layout.BorderPane |
rootNode
The root node of regular sized dialogs
|
Constructor and Description |
---|
Dialog()
Creates an empty Dialog instance, and installs it into the MobileApplication
layer factory . |
Dialog(boolean fullscreen)
Creates an empty fullscreen Dialog if the flag passed in is true, creates an empty regular
Dialog otherwise.
|
Dialog(java.lang.String contentText)
Creates an empty Dialog instance and installs it into the Mobile Application
layer factory . |
Dialog(java.lang.String title,
java.lang.String contentText)
Creates a Dialog instance with the given title and content text, and installs it
into the MobileApplication
layer factory . |
Modifier and Type | Method and Description |
---|---|
javafx.beans.property.BooleanProperty |
autoHideProperty()
This property indicates whether the Dialog should close if a mouse/finger is pressed/tapped
outside of the Dialog.
|
javafx.event.EventDispatchChain |
buildEventDispatchChain(javafx.event.EventDispatchChain tail) |
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
contentProperty()
The content of the Dialog.
|
javafx.beans.property.StringProperty |
contentTextProperty()
The String content of the dialog, setting this property with a non null value will result
in the content being a
Label with the value of this property as the text. |
javafx.collections.ObservableList<javafx.scene.control.ButtonBase> |
getButtons()
A list of buttons to show within the dialog.
|
javafx.scene.Node |
getContent()
Gets the value of the property content.
|
java.lang.String |
getContentText()
Gets the value of the property contentText.
|
javafx.scene.Node |
getGraphic()
Gets the value of the property graphic.
|
java.lang.String |
getId()
Gets the value of the property id.
|
javafx.event.EventHandler<LifecycleEvent> |
getOnCloseRequest()
Gets the value of the property onCloseRequest.
|
javafx.event.EventHandler<LifecycleEvent> |
getOnHidden()
Gets the value of the property onHidden.
|
javafx.event.EventHandler<LifecycleEvent> |
getOnHiding()
Gets the value of the property onHiding.
|
javafx.event.EventHandler<LifecycleEvent> |
getOnShowing()
Gets the value of the property onShowing.
|
javafx.event.EventHandler<LifecycleEvent> |
getOnShown()
Gets the value of the property onShown.
|
javafx.scene.Node |
getTitle()
Gets the value of the property title.
|
java.lang.String |
getTitleText()
Gets the value of the property titleText.
|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
graphicProperty()
The graphic to be displayed in this Dialog.
|
void |
hide()
Hides/closes the dialog.
|
javafx.beans.property.StringProperty |
idProperty()
The id of this
Dialog . |
boolean |
isAutoHide()
Gets the value of the property autoHide.
|
boolean |
isFullscreen()
Indicates whether this dialog is a fullscreen dialog.
|
boolean |
isShowing()
Gets the value of the property showing.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onCloseRequestProperty()
Called when there is an external request to close this Dialog.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onHiddenProperty()
Called just after the Dialog has been hidden.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onHidingProperty()
Called just prior to the Dialog being hidden.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onShowingProperty()
Called just prior to the Dialog being shown.
|
javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> |
onShownProperty()
Called just after the Dialog is shown.
|
void |
setAutoHide(boolean value)
Sets the value of the property autoHide.
|
void |
setContent(javafx.scene.Node content)
Sets the value of the property content.
|
void |
setContentText(java.lang.String text)
Sets the value of the property contentText.
|
void |
setGraphic(javafx.scene.Node graphic)
Sets the value of the property graphic.
|
void |
setId(java.lang.String id)
Sets the value of the property id.
|
void |
setOnCloseRequest(javafx.event.EventHandler<LifecycleEvent> value)
Sets the value of the property onCloseRequest.
|
void |
setOnHidden(javafx.event.EventHandler<LifecycleEvent> value)
Sets the value of the property onHidden.
|
void |
setOnHiding(javafx.event.EventHandler<LifecycleEvent> value)
Sets the value of the property onHiding.
|
void |
setOnShowing(javafx.event.EventHandler<LifecycleEvent> value)
Sets the value of the property onShowing.
|
void |
setOnShown(javafx.event.EventHandler<LifecycleEvent> value)
Sets the value of the property onShown.
|
void |
setResult(T result)
Sets the result to return once the dialog is hidden.
|
void |
setTitle(javafx.scene.Node title)
Sets the value of the property title.
|
void |
setTitleText(java.lang.String text)
Sets the value of the property titleText.
|
java.util.Optional<T> |
showAndWait()
Requests that the dialog be shown.
|
javafx.beans.property.ReadOnlyBooleanProperty |
showingProperty()
Represents whether the Dialog instance is currently showing or not.
|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
titleProperty()
The title of the Dialog.
|
javafx.beans.property.StringProperty |
titleTextProperty()
The String title of the dialog, setting this property with a non null value will result
in the title being a
Label with the value of this property as the text. |
public final javafx.beans.property.ReadOnlyBooleanProperty showingProperty
isShowing()
public final javafx.beans.property.ObjectProperty<javafx.scene.Node> titleProperty
Label
but
it can be any type extending from Node
getTitle()
,
setTitle(Node)
public final javafx.beans.property.StringProperty titleTextProperty
Label
with the value of this property as the text.
This property might not reflect the actual title since no synchronization between
titleProperty()
and titleTextProperty
exists when the title property is setgetTitleText()
,
setTitleText(String)
public final javafx.beans.property.StringProperty contentTextProperty
Label
with the value of this property as the text.
This property might not reflect the actual content since no synchronization between
contentProperty()
and contentTextProperty()
exists when the content property is setgetContentText()
,
setContentText(String)
public final javafx.beans.property.ObjectProperty<javafx.scene.Node> contentProperty
Label
but can be set with any type extending from Node
getContent()
,
setContent(Node)
public final javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty
getGraphic()
,
setGraphic(Node)
public final javafx.beans.property.BooleanProperty autoHideProperty
isAutoHide()
,
setAutoHide(boolean)
public final javafx.beans.property.StringProperty idProperty
Dialog
. This simple string identifier is useful for
finding a specific Dialog within the scene graph. While the id of a Dialog
should be unique within the scene graph, this uniqueness is not enforced.
This is analogous to the "id" attribute on an HTML element
(CSS ID Specification).
For example, if a Dialog is given the id of "myId", then the lookup method can
be used to find this dialog as follows: scene.lookup("#myId");
.
getId()
,
setId(String)
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onShowingProperty
getOnShowing()
,
setOnShowing(EventHandler)
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onShownProperty
getOnShown()
,
setOnShown(EventHandler)
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onHidingProperty
getOnHiding()
,
setOnHiding(EventHandler)
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onHiddenProperty
getOnHidden()
,
setOnHidden(EventHandler)
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onCloseRequestProperty
protected javafx.scene.layout.BorderPane rootNode
public Dialog()
layer factory
.public Dialog(java.lang.String contentText)
layer factory
.
The given string is used as the text of the Label that is set as its content.contentText
- The text to show as the Dialog's content.public Dialog(java.lang.String title, java.lang.String contentText)
layer factory
.title
- The title to show at the top of the dialog.contentText
- The content text below the title.public Dialog(boolean fullscreen)
fullscreen
- Whether the Dialog should be fullscreenpublic final javafx.beans.property.ReadOnlyBooleanProperty showingProperty()
isShowing()
public final boolean isShowing()
public final javafx.beans.property.ObjectProperty<javafx.scene.Node> titleProperty()
Label
but
it can be any type extending from Node
getTitle()
,
setTitle(Node)
public final javafx.scene.Node getTitle()
Label
but
it can be any type extending from Node
public final void setTitle(javafx.scene.Node title)
Label
but
it can be any type extending from Node
public final javafx.beans.property.StringProperty titleTextProperty()
Label
with the value of this property as the text.
This property might not reflect the actual title since no synchronization between
titleProperty()
and titleTextProperty
exists when the title property is setgetTitleText()
,
setTitleText(String)
public final void setTitleText(java.lang.String text)
Label
with the value of this property as the text.
This property might not reflect the actual title since no synchronization between
titleProperty()
and titleTextProperty
exists when the title property is setpublic final java.lang.String getTitleText()
Label
with the value of this property as the text.
This property might not reflect the actual title since no synchronization between
titleProperty()
and titleTextProperty
exists when the title property is setpublic final javafx.beans.property.StringProperty contentTextProperty()
Label
with the value of this property as the text.
This property might not reflect the actual content since no synchronization between
contentProperty()
and contentTextProperty()
exists when the content property is setgetContentText()
,
setContentText(String)
public final void setContentText(java.lang.String text)
Label
with the value of this property as the text.
This property might not reflect the actual content since no synchronization between
contentProperty()
and contentTextProperty()
exists when the content property is setpublic final java.lang.String getContentText()
Label
with the value of this property as the text.
This property might not reflect the actual content since no synchronization between
contentProperty()
and contentTextProperty()
exists when the content property is setpublic final javafx.beans.property.ObjectProperty<javafx.scene.Node> contentProperty()
Label
but can be set with any type extending from Node
getContent()
,
setContent(Node)
public final javafx.scene.Node getContent()
Label
but can be set with any type extending from Node
public final void setContent(javafx.scene.Node content)
Label
but can be set with any type extending from Node
public final javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty()
getGraphic()
,
setGraphic(Node)
public final void setGraphic(javafx.scene.Node graphic)
public final javafx.scene.Node getGraphic()
public final javafx.beans.property.BooleanProperty autoHideProperty()
isAutoHide()
,
setAutoHide(boolean)
public final void setAutoHide(boolean value)
public final boolean isAutoHide()
public final javafx.beans.property.StringProperty idProperty()
Dialog
. This simple string identifier is useful for
finding a specific Dialog within the scene graph. While the id of a Dialog
should be unique within the scene graph, this uniqueness is not enforced.
This is analogous to the "id" attribute on an HTML element
(CSS ID Specification).
For example, if a Dialog is given the id of "myId", then the lookup method can
be used to find this dialog as follows: scene.lookup("#myId");
.
getId()
,
setId(String)
public final void setId(java.lang.String id)
Dialog
. This simple string identifier is useful for
finding a specific Dialog within the scene graph. While the id of a Dialog
should be unique within the scene graph, this uniqueness is not enforced.
This is analogous to the "id" attribute on an HTML element
(CSS ID Specification).
For example, if a Dialog is given the id of "myId", then the lookup method can
be used to find this dialog as follows: scene.lookup("#myId");
.
public final java.lang.String getId()
Dialog
. This simple string identifier is useful for
finding a specific Dialog within the scene graph. While the id of a Dialog
should be unique within the scene graph, this uniqueness is not enforced.
This is analogous to the "id" attribute on an HTML element
(CSS ID Specification).
For example, if a Dialog is given the id of "myId", then the lookup method can
be used to find this dialog as follows: scene.lookup("#myId");
.
public javafx.event.EventDispatchChain buildEventDispatchChain(javafx.event.EventDispatchChain tail)
buildEventDispatchChain
in interface javafx.event.EventTarget
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onShowingProperty()
getOnShowing()
,
setOnShowing(EventHandler)
public final void setOnShowing(javafx.event.EventHandler<LifecycleEvent> value)
public final javafx.event.EventHandler<LifecycleEvent> getOnShowing()
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onShownProperty()
getOnShown()
,
setOnShown(EventHandler)
public final void setOnShown(javafx.event.EventHandler<LifecycleEvent> value)
public final javafx.event.EventHandler<LifecycleEvent> getOnShown()
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onHidingProperty()
getOnHiding()
,
setOnHiding(EventHandler)
public final void setOnHiding(javafx.event.EventHandler<LifecycleEvent> value)
public final javafx.event.EventHandler<LifecycleEvent> getOnHiding()
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onHiddenProperty()
getOnHidden()
,
setOnHidden(EventHandler)
public final void setOnHidden(javafx.event.EventHandler<LifecycleEvent> value)
public final javafx.event.EventHandler<LifecycleEvent> getOnHidden()
public final javafx.beans.property.ObjectProperty<javafx.event.EventHandler<LifecycleEvent>> onCloseRequestProperty()
public final void setOnCloseRequest(javafx.event.EventHandler<LifecycleEvent> value)
public final javafx.event.EventHandler<LifecycleEvent> getOnCloseRequest()
public final javafx.collections.ObservableList<javafx.scene.control.ButtonBase> getButtons()
public final boolean isFullscreen()
public final java.util.Optional<T> showAndWait()
Optional
instance that contains the result from the user
dismissing the dialog.public final void setResult(T result)
result
- The result from the users interaction.public final void hide()