Notification Balloons
Sometimes, it is required to show relevant information without interrupting the developer’s flow. The most general way is to use notification balloons. They inform users of the events or system states related to a project or IDE.
To display a notification, provide two things. First, a notification group to act as a configurable channel. Then, a notification instance itself.
Notification Group
Declare a notification group as an extension in the plugin descriptor. It is registered using the com.intellij.notificationGroup extension point. Set the display type to BALLOON constant. Then, provide a human-readable identifier.
Timeline notification
Next, create a new Notification instance. The constructor takes three arguments:
Notification group ID
Content text
Type (controls the icon that's displayed)
Use the notify method and pass in the current project to show the notification in its associated frame.
By default, a notification is timed, as it will automatically disappear after 10 seconds. However, it will remain in the Notifications tool window, until cleared, in the Timeline section.
Configuring Notifications
Notifications are configured in . Observe the Bagel notification group with Popup type set to Balloon and Show in tool window being checked.
See Notifications Product Help for specific user-facing options.
Notification Icons
Customize the notification icon according to message severity. Use the constants from NotificationType.
Generic information:
INFORMATION.Disruptions or events requiring user action:
WARNING.Critical events or states:
ERROR.
When possible, use a plugin or functionality icon instead of the Information icon. See the Icons section for more information.
Notification Actions
A notification balloon can contain actions, rendered as a link or button.
Chain addAction method with createSimpleExpiring method, which provides a trailing lambda for the action handler. When the user clicks it, the notification dismisses automatically. However, it will stay in the Notification tool window with the hyperlink greyed-out.
Multiple Actions
Anything beyond two actions gets hidden in a More menu. Put the most important actions first.
Notification Title and Body
To give more context, use a title and a body. The title briefly describes what happened, and the body explains the impact or what the user can do about it. The overloaded constructor takes an extra string before the content – that’s the title.
Suggestions
In some cases, the functionality needs to prompt or notify the user to take action or provide input.
Suggestions show the primary action as a noticeable button. Unlike timed notifications, suggestions won’t go away on their own. The user has to act and dismiss them explicitly. Their notification group is configured as STICKY_BALLOON.
To mark the notification as a suggestion, set its suggestion type to true.
Suggestions have a dedicated section in the Notifications tool window.
Tool Window Notifications
A tool window can trigger a long-running operation. For example, the Find in Files action takes a couple of seconds to search for a string in a large project tree, doing that in the background. When there are no matches, a notification balloon is shown. However, instead of the usual location, the notification balloon is displayed directly next to the tool window icon. In the plugin descriptor, declare the notification group with a display type set to TOOL_WINDOW. As the notification group’s notifications are explicitly bound to a specific tool window, provide its identifier in the toolWindowId attribute.
The toolWindowId matches the id value declared in the com.intellij.toolWindow extension.
In the code, use the standard Notification.notify method to show it.
Such notification is automatically dismissed on any keypress or mouse click. Due to space constraints, the notification title should be as short as possible. Additionally, use at most one notification action, which will be rendered as a hyperlink. Generally, the tool window notifications don’t need to be shown in the Notifications tool window. See the corresponding section for the implementation.
Icons
The UI guidelines recommend using a plugin or functionality icon instead of the generic Information icon. Provide an icon along with its accompanying constant. The Notification.setIcon overrides the icon from the constructor argument.
Localization
The notification group identifier is not a technical identifier, but a human-readable string directly mapped to the IDE settings user interface. However, it can be localized.
Make sure that the plugin descriptor declares a plugin resource bundle:
Then declare a key element that contains a localized notification group ID.
Configuring notification display settings
Some use-cases require a specific display configuration for the notification balloons. Use them carefully, as they might go against the default user experience guidelines.
Notification balloons without entries in the Notifications tool window
Occasionally, there are notifications that do not need to be logged in the Notification tool window. This is the standard case with Tool Window notifications. However, there are other usages as well. A Hotswap Reload action or a Breakpoint Hit is shown as notification balloons and then completely hidden. Such a notification group has the isLogByDefault attribute set to false. This matches the Show in tool window option being disabled.
Notifications tool window entry without a notification balloon
To log a new entry into the Notifications tool entry without showing a balloon, configure the displayType to NONE. This matches the Popup type list being set to No popup.
Obsolete API
Previously, there were multiple SDK approaches to notification balloons. They are considered to be obsolete or too complex.
NotificationGroupis considered an internal data structure. Its factory methods are replaced withNotificationconstructor and subsequent builder methods. TheNotificationGroupManager, itsgetNotificationGroupmethod are no longer necessary, as the reference to the notification group is resolved via the notification group identifier.The
Notifications.Bus.notifymethod can be replaced with thenotifymethod on theNotificationinstance.NotificationsManageris considered to be internal. Its methods should be replaced by the corresponding methods in theNotificationclass.
Summary
A notification group is a user-configurable channel for notifications. Directly maps to a configuration item in the IDE settings.
Timeline notification shows for 10 seconds and is automatically dismissed. The primary action is shown as a hyperlink. Uses a
BALLOONconstant in the notification group.Suggestion needs to be dismissed explicitly. The primary action is shown as a button. Uses a
STICKY_BALLONconstant in the notification group. Needs to setsetNotificationType(true)on theNotificationinstance. Suggestions are shown in a dedicated section in the Notifications tool window.Tool Window Notification visually points to the specific tool windows. The primary action is shown as a hyperlink. It is automatically dismissed on click or keypress.
Use the
Notificationclass to create instances, its builder methods to configure, and thenotifymethod to show a notification.