Most operating systems have a concept of tray, as a set of icons visible from the main window that can provide quick access components. On macOS, these are represented as icons across the top menu bar, and on Windows, as icons on the bottom-right near the clock. Linux systems have various approaches that do similar things, and some operating systems have none. Since there is only one tray, it is necessary to add the item only once. The Activator
class can be used to ensure that the TrayItem
is created at startup and removed at shutdown.
Open the
Activator
class, and add two private fields:private TrayItem trayItem; private Image image;
Add the following to the
start
method:final Display display = Display.getDefault(); display.asyncExec(() -> { image = new Image(display, Activator.class.getResourceAsStream("/icons/sample.gif")); Tray tray = display.getSystemTray(); if (tray != null && image != null) { trayItem = new TrayItem...