public class Toast
extends java.lang.Object
On mobile, toasts are used to display simple messages to the user. They are displayed at the bottom of the screen
for a specific amount of time. Developers are advised to use a duration of either LENGTH_SHORT or
LENGTH_LONG.
Calling show() consecutively on different Toasts will put the messages on a FIFO queue, each one will be
shown as soon as the previous one is finished showing.
The following code creates a Button and a Toast and in the event handler of the button calls show()
to show the Toast.
Button button = new Button("Show toast");
Toast toast = new Toast("This is a toast!");
button.setOnAction(event -> toast.show());
| Type | Property | Description |
|---|---|---|
javafx.beans.property.ObjectProperty<javafx.util.Duration> |
duration |
The time the Toast is shown.
|
javafx.beans.property.StringProperty |
id |
The id of this
Toast. |
javafx.beans.property.StringProperty |
message |
The message to display.
|
| Modifier and Type | Field | Description |
|---|---|---|
static javafx.util.Duration |
LENGTH_LONG |
A long amount of time to display the message - 3500 ms.
|
static javafx.util.Duration |
LENGTH_SHORT |
A short amount of time to display the message - 2000 ms.
|
| Constructor | Description |
|---|---|
Toast() |
Creates an empty Toast message with a duration of
LENGTH_SHORT. |
Toast(java.lang.String message) |
Creates a Toast message with a duration of
LENGTH_SHORT. |
Toast(java.lang.String message,
javafx.util.Duration duration) |
Creates a Toast message with a given duration.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
cancel() |
If the Toast is currently showing, calling this method will hide it immediately
and show the next Toast in queue.
|
javafx.beans.property.ObjectProperty<javafx.util.Duration> |
durationProperty() |
The time the Toast is shown.
|
javafx.util.Duration |
getDuration() |
Gets the value of the property duration.
|
java.lang.String |
getId() |
Gets the value of the property id.
|
java.lang.String |
getMessage() |
Gets the value of the property message.
|
javafx.beans.property.StringProperty |
idProperty() |
The id of this
Toast. |
javafx.beans.property.StringProperty |
messageProperty() |
The message to display.
|
void |
setDuration(javafx.util.Duration duration) |
Sets the value of the property duration.
|
void |
setId(java.lang.String id) |
Sets the value of the property id.
|
void |
setMessage(java.lang.String text) |
Sets the value of the property message.
|
void |
show() |
Shows the Toast to the user.
|
public final javafx.beans.property.StringProperty messageProperty
getMessage(),
setMessage(String)public final javafx.beans.property.ObjectProperty<javafx.util.Duration> durationProperty
getDuration(),
setDuration(Duration)public final javafx.beans.property.StringProperty idProperty
Toast. This simple string identifier is useful for
finding a specific Toast within the scene graph. While the id of a Toast
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 Toast is given the id of "myId", then the lookup method can
be used to find this toast as follows: scene.lookup("#myId");.
getId(),
setId(String)public static final javafx.util.Duration LENGTH_SHORT
public static final javafx.util.Duration LENGTH_LONG
public Toast()
LENGTH_SHORT.public Toast(java.lang.String message)
LENGTH_SHORT.message - the message to display in the Toast control.public Toast(java.lang.String message,
javafx.util.Duration duration)
message - the message to display in the Toast control.duration - the duration the Toast message is shown.public final void setMessage(java.lang.String text)
public final java.lang.String getMessage()
public final javafx.beans.property.StringProperty messageProperty()
getMessage(),
setMessage(String)public final void setDuration(javafx.util.Duration duration)
public final javafx.util.Duration getDuration()
public final javafx.beans.property.ObjectProperty<javafx.util.Duration> durationProperty()
getDuration(),
setDuration(Duration)public final javafx.beans.property.StringProperty idProperty()
Toast. This simple string identifier is useful for
finding a specific Toast within the scene graph. While the id of a Toast
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 Toast is given the id of "myId", then the lookup method can
be used to find this toast as follows: scene.lookup("#myId");.
getId(),
setId(String)public final void setId(java.lang.String id)
Toast. This simple string identifier is useful for
finding a specific Toast within the scene graph. While the id of a Toast
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 Toast is given the id of "myId", then the lookup method can
be used to find this toast as follows: scene.lookup("#myId");.
public final java.lang.String getId()
Toast. This simple string identifier is useful for
finding a specific Toast within the scene graph. While the id of a Toast
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 Toast is given the id of "myId", then the lookup method can
be used to find this toast as follows: scene.lookup("#myId");.
public void show()
public void cancel()