Class NotificationPane

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class NotificationPane extends Control
The NotificationPane control is a container control that, when prompted by the show() method, will show a non-modal message to the user. The notification appears as a bar that will slide in to their application window, either from the top or the bottom of the NotificationPane (based on showFromTopProperty()) wherever that may be in the scenegraph.

Alternative Styling

As is visible in the screenshots further down this documentation, there are two different styles supported by the NotificationPane control. Firstly, there is the default style based on the JavaFX Modena look. The alternative style is what is currently referred to as the 'dark' look. To enable this functionality, simply do the following:

 
 NotificationPane notificationPane = new NotificationPane();   
 notificationPane.getStyleClass().add(NotificationPane.STYLE_CLASS_DARK);
 

Screenshots

To better explain NotificationPane, here is a table showing both the default and dark look for the NotificationPane on a Windows machine (although that shouldn't impact the visuals a great deal). Also, to show the difference between top and bottom placement, these two modes are also captured in the screenshots below:

Setting

Screenshot

Light theme from top:
Screenshot of NotificationPane - Light theme from top
Light theme from bottom:
Screenshot of NotificationPane - Light theme from bottom
Dark theme from top:
Screenshot of NotificationPane - Dark theme from top
Dark theme from bottom:
Screenshot of NotificationPane - Dark theme from bottom

Code Examples

NotificationPane is a conceptually very simple control - you simply create your user interface as you normally would, and then wrap it inside the NotificationPane. You can then show a notification bar on top of your content simply by calling show() on the notification bar. Here is an example:

 
 // Create a WebView
 WebView webView = new WebView();
 
 // Wrap it inside a NotificationPane
 NotificationPane notificationPane = new NotificationPane(webView);
 
 // and put the NotificationPane inside a Tab
 Tab tab1 = new Tab("Tab 1");
 tab1.setContent(notificationPane);
 
 // and the Tab inside a TabPane. We just have one tab here, but of course 
 // you can have more!
 TabPane tabPane = new TabPane();
 tabPane.getTabs().addAll(tab1);
 

Now that the notification pane is installed inside the tab, at some point later in you application lifecycle, you can do something like the following to have the notification bar slide into view:

 
 notificationPane.setText("Do you want to save your password?");
 notificationPane.getActions().add(new AbstractAction("Save Password") {
     public void execute(ActionEvent ae) {
         // do save...
           
         // then hide...
         notificationPane.hide();
     }
 }
See Also:
  • Property Details

  • Field Details

    • STYLE_CLASS_DARK

      public static final String STYLE_CLASS_DARK
      Static fields
      See Also:
    • ON_SHOWING

      public static final EventType<Event> ON_SHOWING
      Called when the NotificationPane will be shown.
    • ON_SHOWN

      public static final EventType<Event> ON_SHOWN
      Called when the NotificationPane shows.
    • ON_HIDING

      public static final EventType<Event> ON_HIDING
      Called when the NotificationPane will be hidden.
    • ON_HIDDEN

      public static final EventType<Event> ON_HIDDEN
      Called when the NotificationPane is hidden.
  • Constructor Details

    • NotificationPane

      public NotificationPane()
      Creates an instance of NotificationPane with no content, text, graphic properties set, and no actions specified.
    • NotificationPane

      public NotificationPane(Node content)
      Creates an instance of NotificationPane with the content property set, but no text or graphic property set, and no actions specified.
      Parameters:
      content - The content to show in the NotificationPane behind where the notification bar will appear, that is, the content will notappear in the notification bar.
  • Method Details

    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class Control
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class Region
    • contentProperty

      public final ObjectProperty<Node> contentProperty()
      The content property represents what is shown in the scene that is not within the notification bar. In other words, it is what the notification bar should appear on top of. For example, in the scenario where you are using a WebView to show to the user websites, and you want to popup up a notification bar to save a password, the content would be the WebView. Refer to the NotificationPane class documentation for more details.
      Returns:
      A property representing the content of this NotificationPane.
    • setContent

      public final void setContent(Node value)
      Set the content to be shown in the scene, that is not within the notification bar.
      Parameters:
      value -
    • getContent

      public final Node getContent()
      Returns:
      The content shown in the scene.
    • textProperty

      public final StringProperty textProperty()
      The text property represents the text to show within the popup notification bar that appears on top of the content that is within the NotificationPane.
      See Also:
    • setText

      public final void setText(String value)
      Sets the text to show within the popup notification bar that appears on top of the content.
      Parameters:
      value -
    • getText

      public final String getText()
      Returns:
      the text showing within the popup notification bar that appears on top of the content.
    • graphicProperty

      public final ObjectProperty<Node> graphicProperty()
      The graphic property represents the Node to show within the popup notification bar that appears on top of the content that is within the NotificationPane. Despite the term 'graphic', this can be an arbitrarily complex scenegraph in its own right.
      See Also:
    • setGraphic

      public final void setGraphic(Node value)
      Sets the Node to show within the popup notification bar.
      Parameters:
      value -
    • getGraphic

      public final Node getGraphic()
      Returns:
      the Node to show within the popup notification bar.
    • showingProperty

      public final ReadOnlyBooleanProperty showingProperty()
      A read-only property that represents whether the notification bar popup should be showing to the user or not. To toggle visibility, use the show() and hide() methods.
      See Also:
    • isShowing

      public final boolean isShowing()
      Returns:
      whether the notification bar is currently showing.
    • showFromTopProperty

      public final BooleanProperty showFromTopProperty()
      A property representing whether the notification bar should appear from the top or the bottom of the NotificationPane area. By default it will appear from the top, but this can be changed by setting this property to false.
      See Also:
    • setShowFromTop

      public final void setShowFromTop(boolean value)
      Sets whether the notification bar should appear from the top or the bottom of the NotificationPane area.
      Parameters:
      value -
    • isShowFromTop

      public final boolean isShowFromTop()
      Returns:
      whether the notification bar is appearing from the top or the bottom of the NotificationPane area.
    • onShowingProperty

      public final ObjectProperty<EventHandler<Event>> onShowingProperty()
      See Also:
    • setOnShowing

      public final void setOnShowing(EventHandler<Event> value)
      Called just prior to the NotificationPane being shown.
    • getOnShowing

      public final EventHandler<Event> getOnShowing()
      Gets the value of the property onShowing.
      Property description:
    • onShownProperty

      public final ObjectProperty<EventHandler<Event>> onShownProperty()
      See Also:
    • setOnShown

      public final void setOnShown(EventHandler<Event> value)
      Called just after the NotificationPane is shown.
    • getOnShown

      public final EventHandler<Event> getOnShown()
      Gets the value of the property onShown.
      Property description:
    • onHidingProperty

      public final ObjectProperty<EventHandler<Event>> onHidingProperty()
      See Also:
    • setOnHiding

      public final void setOnHiding(EventHandler<Event> value)
      Called just prior to the NotificationPane being hidden.
    • getOnHiding

      public final EventHandler<Event> getOnHiding()
      Gets the value of the property onHiding.
      Property description:
    • onHiddenProperty

      public final ObjectProperty<EventHandler<Event>> onHiddenProperty()
      See Also:
    • setOnHidden

      public final void setOnHidden(EventHandler<Event> value)
      Called just after the NotificationPane has been hidden.
    • getOnHidden

      public final EventHandler<Event> getOnHidden()
      Gets the value of the property onHidden.
      Property description:
    • closeButtonVisibleProperty

      public final BooleanProperty closeButtonVisibleProperty()
      A property representing whether the close button in the NotificationPane should be visible or not. By default it will appear but this can be changed by setting this property to false.
      See Also:
    • setCloseButtonVisible

      public final void setCloseButtonVisible(boolean value)
      Sets whether the close button in NotificationPane should be visible.
      Parameters:
      value -
    • isCloseButtonVisible

      public final boolean isCloseButtonVisible()
      Returns:
      whether the close button in NotificationPane is visible.
    • getActions

      public final ObservableList<Action> getActions()
      Observable list of actions used for the actions area of the notification bar. Modifying the contents of this list will change the actions available to the user.
      Returns:
      The ObservableList of actions available to the user.
    • show

      public void show()
      Call this to make the notification bar appear on top of the content of this NotificationPane. If the notification bar is already showing this will be a no-op.
    • show

      public void show(String text)
      Shows the NotificationPane with the content and text property set, but no graphic property set, and no actions specified.
      Parameters:
      text - The text to show in the notification pane.
    • show

      public void show(String text, Node graphic)
      Shows the NotificationPane with the content, text and graphic properties set, but no actions specified.
      Parameters:
      text - The text to show in the notification pane.
      graphic - The node to show in the notification pane.
    • show

      public void show(String text, Node graphic, Action... actions)
      Shows the NotificationPane with the content, text and graphic property set, and the provided actions copied into the actions list.
      Parameters:
      text - The text to show in the notification pane.
      graphic - The node to show in the notification pane.
      actions - The actions to show in the notification pane.
    • hide

      public void hide()
      Call this to make the notification bar disappear from the content of this NotificationPane. If the notification bar is already hidden this will be a no-op.
    • getUserAgentStylesheet

      protected final String getUserAgentStylesheet(Class<?> clazz, String fileName)
      A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once. Caches the external form of the resource.
      Parameters:
      clazz - the class used for the resource lookup
      fileName - the name of the user agent stylesheet
      Returns:
      the external form of the user agent stylesheet (the path)