How to show notification in IntelliJ?

It turned out how to show one of these small messages about notification bubbles in the upper right corner of the screen, answer below.

+7
java intellij-idea intellij-plugin
source share
2 answers

Turns out you need to create an instance of NotificationGroup and then use it to create Notifications and pass the notification and Project Notifications.Bus.notify ().

public class VoiceApplicationComponentImpl implements ApplicationComponent, VoiceApplicationComponent { ... public static final NotificationGroup GROUP_DISPLAY_ID_INFO = new NotificationGroup("My notification group", NotificationDisplayType.BALLOON, true); ... void showMyMessage(String message) { ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { Notification notification = GROUP_DISPLAY_ID_INFO.createNotification(message, NotificationType.ERROR); Project[] projects = ProjectManager.getInstance().getOpenProjects(); Notifications.Bus.notify(notification, projects[0]); } }); } 

Note: you will probably have a better way to get the current project, for now I just assume there is one open project. This means that my method does not work at startup (the array of projects is empty).

Another note: you probably won’t need to wrap invokeLater, but I did it because I was calling showMyMessage in another thread.

+11
source share

it will be better!

 StatusBar statusBar = WindowManager.getInstance() .getStatusBar(DataKeys.PROJECT.getData(actionEvent.getDataContext())); JBPopupFactory.getInstance() .createHtmlTextBalloonBuilder(htmlText, messageType, null) .setFadeoutTime(7500) .createBalloon() .show(RelativePoint.getCenterOf(statusBar.getComponent()), Balloon.Position.atRight); 

link:
1. original link
2. enter the link here

0
source share

All Articles