Class Notifications

java.lang.Object
org.controlsfx.control.Notifications

public class Notifications extends Object
An API to show popup notification messages to the user in the corner of their screen, unlike the NotificationPane which shows notification messages within your application itself.

Screenshot

The following screenshot shows a sample notification rising from the bottom-right corner of my screen:

Screenshot of Notifications

Code Example:

To create the notification shown in the screenshot, simply do the following:

 
 Notifications.create()
              .title("Title Text")
              .text("Hello World 0!")
              .showWarning();
 
 

When there are too many notifications on the screen, one can opt to collapse the notifications into a single notification using threshold(int, Notifications).

 
 Notifications.create()
              .title("Title Text")
              .text("Hello World 0!")
              .threshold(3, Notifications.create().title("Collapsed Notification"))
              .showWarning();
 
 
  • Method Summary

    Modifier and Type
    Method
    Description
    action(Action... actions)
    Specifies the actions that should be shown in the notification as buttons.
    Call this to begin the process of building a notification to show.
    Specifies that the notification should use the built-in dark styling, rather than the default 'modena' notification style (which is a light-gray).
    Gets the style classes that would be added to the NotificationBar.
    graphic(javafx.scene.Node graphic)
    Specifies the graphic to show in the notification.
    hideAfter(javafx.util.Duration duration)
    Specifies the duration that the notification should show, after which it will be hidden.
    Specifies that the close button in the top-right corner of the notification should not be shown.
    onAction(javafx.event.EventHandler<javafx.event.ActionEvent> onAction)
    Specifies what to do when the user clicks on the notification (in addition to the notification hiding, which happens whenever the notification is clicked on).
    owner(Object owner)
    The dialog window owner - which can be Screen, Window or Node.
    position(javafx.geometry.Pos position)
    Specifies the position of the notification on screen, by default it is bottom-right.
    void
    Instructs the notification to be shown.
    void
    Instructs the notification to be shown, and that it should use the built-in 'confirm' graphic.
    void
    Instructs the notification to be shown, and that it should use the built-in 'error' graphic.
    void
    Instructs the notification to be shown, and that it should use the built-in 'information' graphic.
    void
    Instructs the notification to be shown, and that it should use the built-in 'warning' graphic.
    styleClass(String... styleClasses)
    Specifies the style classes to add to the NotificationBar.
    text(String text)
    Specifies the text to show in the notification.
    threshold(int threshold, Notifications thresholdNotification)
    Collapses all the current notifications into a single notification when the number of notifications exceed the threshold limit.
    title(String title)
    Specifies the title to show in the notification.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static Notifications create()
      Call this to begin the process of building a notification to show.
    • text

      public Notifications text(String text)
      Specifies the text to show in the notification.
    • title

      public Notifications title(String title)
      Specifies the title to show in the notification.
    • graphic

      public Notifications graphic(javafx.scene.Node graphic)
      Specifies the graphic to show in the notification.
    • position

      public Notifications position(javafx.geometry.Pos position)
      Specifies the position of the notification on screen, by default it is bottom-right.
    • owner

      public Notifications owner(Object owner)
      The dialog window owner - which can be Screen, Window or Node. If specified, the notifications will be inside the owner, otherwise the notifications will be shown within the whole primary (default) screen.
    • hideAfter

      public Notifications hideAfter(javafx.util.Duration duration)
      Specifies the duration that the notification should show, after which it will be hidden.
    • onAction

      public Notifications onAction(javafx.event.EventHandler<javafx.event.ActionEvent> onAction)
      Specifies what to do when the user clicks on the notification (in addition to the notification hiding, which happens whenever the notification is clicked on).
    • darkStyle

      public Notifications darkStyle()
      Specifies that the notification should use the built-in dark styling, rather than the default 'modena' notification style (which is a light-gray).
    • styleClass

      public Notifications styleClass(String... styleClasses)
      Specifies the style classes to add to the NotificationBar.
    • hideCloseButton

      public Notifications hideCloseButton()
      Specifies that the close button in the top-right corner of the notification should not be shown.
    • action

      public Notifications action(Action... actions)
      Specifies the actions that should be shown in the notification as buttons.
    • threshold

      public Notifications threshold(int threshold, Notifications thresholdNotification)
      Collapses all the current notifications into a single notification when the number of notifications exceed the threshold limit. A value of zero will disable the threshold behavior.
      Parameters:
      threshold - The number of notifications to show before they can be collapsed into a single notification.
      thresholdNotification - The notification to show when threshold is reached.
    • showWarning

      public void showWarning()
      Instructs the notification to be shown, and that it should use the built-in 'warning' graphic.
    • showInformation

      public void showInformation()
      Instructs the notification to be shown, and that it should use the built-in 'information' graphic.
    • showError

      public void showError()
      Instructs the notification to be shown, and that it should use the built-in 'error' graphic.
    • showConfirm

      public void showConfirm()
      Instructs the notification to be shown, and that it should use the built-in 'confirm' graphic.
    • show

      public void show()
      Instructs the notification to be shown.
    • getStyleClass

      public List<String> getStyleClass()
      Gets the style classes that would be added to the NotificationBar.