Skip to main content
A flexible alert component for displaying informational messages, warnings, errors, and success notifications to users.

Constructor

JAlert(String title)
constructor
Creates a new alert with only a title.
JAlert(String title, String description)
constructor
Creates a new alert with title and description.

Methods

setIcon(Node icon)
JAlert
Sets a custom icon for the alert.
setIcon(JIcon iconEnum)
JAlert
Sets an icon using the JIcon enumeration.
setDismissible(boolean dismissible)
JAlert
Makes the alert dismissible with a close button.
addClass(String... styleClasses)
JAlert
Adds custom CSS style classes to the alert.

Usage Example

// Basic alert
JAlert alert = new JAlert("Success!", "Your changes have been saved.");
alert.addClass("alert-success");

// Alert with icon
JAlert warning = new JAlert("Warning", "Please review your input.");
warning.setIcon(JIcon.WARNING)
       .addClass("alert-warning");

// Dismissible alert
JAlert info = new JAlert("Info", "This is an informational message.");
info.setDismissible(true)
    .addClass("alert-info");

// Danger alert with custom icon
SVGPath errorIcon = new SVGPath();
errorIcon.setContent("M12 2L2 22h20L12 2z");
JAlert danger = new JAlert("Error");
danger.setIcon(errorIcon)
      .addClass("alert-danger");

Common Alert Variants

Use the addClass() method with these common variants:
  • .alert-primary - Primary alert style
  • .alert-success - Success message (green)
  • .alert-danger - Error or critical warning (red)
  • .alert-warning - Warning message (yellow/orange)
  • .alert-info - Informational message (blue)
  • .alert-secondary - Secondary style (gray)

Style Classes

  • .alert - Main container
  • .alert-icon-container - Icon container
  • .alert-icon - Icon element
  • .alert-title - Title label
  • .alert-description - Description label
  • .alert-dismiss-container - Dismiss button container
  • .alert-dismiss-btn - Dismiss button
  • .alert-close-icon - Close icon SVG

Build docs developers (and LLMs) love