Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show a notification in IntelliJ?

Figured out how to show one of those little notification bubble messages in the top right of the screen, answer below.

like image 775
Verdagon Avatar asked Oct 04 '15 00:10

Verdagon


People also ask

How do I see errors and warnings in IntelliJ?

Navigate to detected problems in the widget or by pressing F2 or Shift+F2 accordingly. By default, the IDE will navigate you to problems according to their severity: errors > warnings > weak warnings > server problems > typos. , select 'Next Error' Action (F2) Goes Through, and enable All Problems.

How do I show annotations in IntelliJ?

You can configure the IDE to show inferred annotations right in your code. Press Ctrl+Alt+S to open the IDE settings and select Editor | Inlay Hints | Annotations | Java. Select the Inferred annotations checkbox.

How do I change display settings in IntelliJ?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), select Appearance & Behavior | Appearance. Select the UI theme from the Theme list: IntelliJ Light: Traditional light theme for IntelliJ-based IDEs.

What is status bar in IntelliJ?

Last modified: 26 September 2022. Product Help: Status bar. The IntelliJ Platform allows plugins to extend the IDE status bar with additional custom widgets. Status bar widgets are small UI elements that allow providing users with useful information and settings for the current file, project, IDE, etc.


1 Answers

Turns out, you have to make a NotificationGroup instance, and then use that to make a Notification, and pass the notification and the Project to 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'll probably have a better way to get the current Project, right now I just assume there's one open project. This means my method doesn't work on startup (projects array is empty).

Another note: you'll probably not need to wrap with the invokeLater but I did, because I was calling showMyMessage in a different thread.

like image 198
Verdagon Avatar answered Sep 23 '22 07:09

Verdagon