T
- The return type of the showAndWait()
method.public class Dialog<T>
extends java.lang.Object
implements javafx.event.EventTarget
A Dialog is composed of 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("The title"));
dialog.setContent(new Label("The content text");
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 tipically used when you need the user to insert data into a long form
that wouldn't fit nicely in a regular sized Dialog.
Alert
,
TimePicker
,
DatePicker
Type | Property and Description |
---|---|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
content
The content of the Dialog.
|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
graphic
The graphic to be displayed in 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.VBox |
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 title)
Creates an empty Dialog instance with the given title, and installs it
into the MobileApplication
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.event.EventDispatchChain |
buildEventDispatchChain(javafx.event.EventDispatchChain tail) |
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
contentProperty()
The content of the Dialog.
|
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.
|
javafx.scene.Node |
getGraphic()
Gets the value of the property graphic.
|
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.
|
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 |
setContent(javafx.scene.Node content)
Sets the value of the property content.
|
void |
setGraphic(javafx.scene.Node graphic)
Sets the value of the property graphic.
|
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.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.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.VBox rootNode
public Dialog()
layer factory
.public Dialog(java.lang.String title)
layer factory
.title
- The title to show at the top of the dialog.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()
public final void setTitle(javafx.scene.Node title)
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)
public final java.lang.String getTitleText()
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.scene.Node getContent()
public final void setContent(javafx.scene.Node content)
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 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()