找出如何在屏幕右上方顯示其中一個小通知氣泡消息,請在下面回答。如何在IntelliJ中顯示通知?
7
A
回答
11
原來,您必須製作一個NotificationGroup實例,然後使用它來進行通知,並將通知和項目傳遞給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]);
}
});
}
注意:您可能有更好的方式來獲得當前的項目,現在我只是假設有一個打開的項目。這意味着我的方法在啓動時不起作用(項目數組爲空)。
另一個說明:你可能不需要用invokeLater包裝,但我做了,因爲我在不同的線程中調用showMyMessage。
0
這樣會更好!
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);
相關問題
- 1. 如何在IOS中顯示通知
- 2. 如何在Android中顯示此通知?
- 3. 如何在iWatch中顯示通知?
- 4. 如何在asp.net中顯示通知
- 5. 如何在android中顯示通知?
- 6. 如何在Windows通知欄中顯示彈出通知
- 7. 在android中顯示通知
- 8. 在MirrorLink中顯示通知
- 9. 如何在通知顯示在後臺之前處理通知?
- 10. 如何在IntelliJ中顯示水平線?
- 11. 如何在tizen上顯示通知
- 12. 如何在科爾多瓦的通知區域顯示通知?
- 13. 顯示通知
- 14. 如何在狀態欄中顯示圖標而不在通知抽屜中顯示通知?
- 15. 如何在手錶套件中顯示通知,其中iPhone應用程序已顯示通知
- 16. Intellij IDEA中的漢字 - 如何顯示?
- 17. 在Android中,如何獲取給定通知ID的當前顯示通知?
- 18. 如何在win 8中顯示吐司通知或彈出通知?
- 19. 如何顯示通知抽屜中不存在的應用內通知Snapchat
- 20. 如何在離子應用程序中顯示圖片中顯示的通知
- 21. 安卓:如何顯示通知文本
- 22. 如何顯示本地通知 - Worklight
- 23. 如何關閉突出顯示通知?
- 24. 如何用按鈕顯示大通知?
- 25. 如何顯示iOS 5通知?
- 26. 如何顯示擡頭通知android
- 27. 如何讓QWebView顯示桌面通知?
- 28. 如何創建「顯示通知」checkboxpreferene
- 29. 如何顯示通知插件更新
- 30. 如何使用C#顯示通知?
是否有人知道爲什麼'ApplicationManager.getApplication()invokeLater'是必要的[商務部](http://www.jetbrains.org/ intellij/sdk/docs/user_interface_components/notifications.html)沒有提到它 –
@ robin.thoni invokeLater()是一個swing方法,它允許在事件分派線程下堆疊ui任務,這是唯一允許執行的線程ui任務...這與swing比intellij api更相關,儘管...不應該在文檔中。 – ALTN
@Verdagon您應該使用Project project = e.getData(LangDataKeys.PROJECT)來獲取您當前的項目參考,否則當多個項目打開時,通知有風險顯示在錯誤的項目下。 e是您從行動課程中獲得的AnActionEvent。還要確保你調用invokeLater可運行的e.getData(LangDataKeys.PROJECT),否則將在運行時拋出異常。出於某種原因,intellij不允許在事件派發線程下調用getData。 – ALTN