Display numbers on a tray icon with SWT

两盒软妹~` 提交于 2019-12-02 04:06:47

问题


I would like to show some numbers on my tray icon indicating a number of events that happened to the user like what is done in this facebook notifications icons:

Do you think that it is possible ?

Thank you


回答1:


You can do this using the TaskBar and TaskItem classes although it may not work on all platforms.

TaskBar taskBar = Display.getDefault().getSystemTaskBar();
// TODO may return null if not supported on the platform

// Get application item

TaskItem taskItem = taskBar.getItem(null);
if (taskItem != null)
  taskItem.setOverlayText("your text");

Also try:

TaskItem taskItem = taskBar.getItem(shell);

where shell is your main application shell. The TaskItem JavaDoc suggests trying both methods of getting the TaskItem:

For better cross platform support, the application code should first try to set this feature on the TaskItem for the main shell then on the TaskItem for the application.



来源:https://stackoverflow.com/questions/33104851/display-numbers-on-a-tray-icon-with-swt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!