Class Toast


  • 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.

    Example

    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());
     
     

    Screenshot of Toast control

    Since:
    4.0.0
    • Constructor Detail

      • Toast

        public Toast​(String message)
        Creates a Toast message with a duration of Message.LENGTH_SHORT.
        Parameters:
        message - the message to display in the Toast control.
      • Toast

        public Toast​(String message,
                     Duration duration)
        Creates a Toast message with a given duration.
        Parameters:
        message - the message to display in the Toast control.
        duration - the duration the Toast message is shown.
    • Method Detail

      • show

        public void show()
        Shows the Message immediately, if no other message is showing. If a message is already showing, it gets added to the waiting queue and will show when its turn arrives.
        Specified by:
        show in class Message
      • cancel

        public void cancel()
        If the Message is currently showing, calling this method will hide it immediately and show the next Message in queue. If the Message is waiting in the queue, calling this method removes the Message from the queue and the Message is never shown.
        Specified by:
        cancel in class Message