Display numbers on a tray icon with SWT

后端 未结 1 828
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-22 09:01

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:

<
相关标签:
1条回答
  • 2021-01-22 09:36

    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.

    0 讨论(0)
提交回复
热议问题