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 and Description |
|---|---|
javafx.beans.property.ObjectProperty<javafx.util.Duration> |
duration
The time the Toast is shown.
|
javafx.beans.property.StringProperty |
message
The message to display.
|
| Modifier and Type | Field and 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 and 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 and Description |
|---|---|
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 |
getMessage()
Gets the value of the property message.
|
javafx.beans.property.StringProperty |
messageProperty()
The message to display.
|
void |
setDuration(javafx.util.Duration duration)
Sets the value of the property duration.
|
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 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 void show()