Skip to main content
A toast notification component that displays temporary messages in a popup overlay, automatically disappearing after a set duration.

Constructor

JToast()
constructor
Creates a new toast notification.

Enums

Type

Defines the toast notification type:
  • DEFAULT - Default toast style
  • SUCCESS - Success message (green)
  • DANGER - Error message (red)
  • WARNING - Warning message (yellow/orange)
  • INFO - Information message (blue)

Position

Defines where the toast appears:
  • TOP_RIGHT - Top right corner
  • TOP_LEFT - Top left corner
  • BOTTOM_RIGHT - Bottom right corner
  • BOTTOM_LEFT - Bottom left corner
  • TOP_CENTER - Top center
  • BOTTOM_CENTER - Bottom center

Methods

show(Window owner, String title, String message, Type type, Position position, Duration duration)
void
Displays the toast notification.
show(Window owner)
void
Shows a toast with previously configured pending values.

Static Helper Methods

JToast.show(Window owner, String message, Type type, Position pos, int durationMillis)
void
Quick static method to show a toast without title.
JToast.show(Window owner, String title, String message, Type type, Position pos, int durationMillis)
void
Quick static method to show a toast with title.
JToast.make(String title, String message, Type type, int durationMillis)
JToast
Factory method for creating a toast with chaining support.
returns
JToast
A configured JToast instance ready to show

Usage Examples

Static Quick Usage

// Simple toast
JToast.show(window, "Changes saved!", 
    JToast.Type.SUCCESS, 
    JToast.Position.BOTTOM_RIGHT, 
    3000);

// Toast with title
JToast.show(window, "Error", "Failed to save changes", 
    JToast.Type.DANGER, 
    JToast.Position.TOP_CENTER, 
    5000);

Instance Usage

JToast toast = new JToast();
toast.show(window, 
    "Success", 
    "Your profile has been updated", 
    JToast.Type.SUCCESS, 
    JToast.Position.BOTTOM_RIGHT, 
    Duration.millis(3000));

Factory Method with Chaining

JToast.make("Info", "New messages available", 
    JToast.Type.INFO, 4000)
    .show(window);

Persistent Toast

// Pass null duration for a toast that doesn't auto-close
JToast toast = new JToast();
toast.show(window, null, "Click X to close", 
    JToast.Type.DEFAULT, 
    JToast.Position.TOP_RIGHT, 
    null);

Features

  • Auto-close with configurable duration
  • Manual close button (X)
  • Multiple position options
  • Type-based styling (success, danger, warning, info)
  • Optional title
  • Smooth fade-in animation
  • Non-blocking overlay

Style Classes

  • .j-toast - Main container
  • .j-toast-success - Success variant
  • .j-toast-danger - Danger variant
  • .j-toast-warning - Warning variant
  • .j-toast-info - Info variant
  • .j-toast-title - Title label
  • .j-toast-message - Message label
  • .j-toast-close - Close button

Build docs developers (and LLMs) love