public class Toast extends Message
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.
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.
Default duration is Message.LENGTH_SHORT
.
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());
LENGTH_LONG, LENGTH_SHORT
Constructor and Description |
---|
Toast()
Creates an empty Toast message with a duration of
Message.LENGTH_SHORT . |
Toast(java.lang.String message)
Creates a Toast message with a duration of
Message.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 |
---|---|
void |
cancel()
If the Message is currently showing, calling this method will hide it immediately
and show the next Message in queue.
|
void |
show()
Shows the Message immediately, if no other message is showing.
|
durationProperty, getDuration, getId, getMessage, idProperty, messageProperty, setDuration, setId, setMessage
public Toast()
Message.LENGTH_SHORT
.public Toast(java.lang.String message)
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 void show()
public void cancel()