Class SystemTray
An icon in the desktop system tray (the menu bar extras on macOS, the
notification area on Windows and Linux), with a tooltip, a menu and a
click listener. Mobile platforms have no tray: #isSupported() answers
false there and every other call does nothing. On Linux the icon needs an
XEmbed tray: a Wayland session answers false, and stock GNOME without an
AppIndicator extension shows nothing although the call succeeds.
if (SystemTray.isSupported()) {
Image icon = FontImage.createMaterial(FontImage.MATERIAL_CLOUD, "Label", 4);
SystemTray.show(icon, "My App");
SystemTray.addMenuItem("Open", new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Log.p("Open selected");
}
});
SystemTray.addClickListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Log.p("Tray icon clicked");
}
});
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdds a listener called on the EDT when the tray icon is clicked.static voidaddMenuItem(String label, ActionListener action) Appends an item to the tray menu.static voidRemoves every menu item.static voidCalled by the port on the EDT when the tray icon is clicked.static voidfireMenuItem(int index) Called by the port on the EDT when a menu item is chosen.static intThe number of menu items.static StringThe current tooltip.static voidhide()Removes the tray icon.static booleanTrue while the tray icon is shown.static booleanTrue when the platform shows a tray icon.static voidRemoves a click listener.static voidsetImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use onlystatic voidsetTooltip(String tooltip) Changes the tooltip.static voidShows the tray icon, or updates it when it is already shown.
-
Method Details
-
setImplementation
public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
Parameters
impl: implementation instance
-
isSupported
public static boolean isSupported()True when the platform shows a tray icon.
Returns
true on a desktop platform with a system tray
-
show
-
hide
public static void hide()Removes the tray icon. The menu and listeners are kept for the next#show(Image, String). -
isShowing
public static boolean isShowing()True while the tray icon is shown.
Returns
true after
#show(Image, String)and before#hide() -
setTooltip
Changes the tooltip.
Parameters
tooltip: the tooltip, may be null
-
getTooltip
The current tooltip.
Returns
the tooltip or null
-
addMenuItem
Appends an item to the tray menu.
Parameters
label: the item textaction: called on the EDT when the item is chosen
-
clearMenu
public static void clearMenu()Removes every menu item. -
getMenuItemCount
public static int getMenuItemCount()The number of menu items.
Returns
the menu item count
-
addClickListener
Adds a listener called on the EDT when the tray icon is clicked.
Parameters
l: the listener
-
removeClickListener
Removes a click listener.
Parameters
l: the listener
-
fireClicked
public static void fireClicked()Called by the port on the EDT when the tray icon is clicked. Not meant for application code. -
fireMenuItem
public static void fireMenuItem(int index) Called by the port on the EDT when a menu item is chosen. Not meant for application code.
Parameters
index: the item position, as passed to the port
-