Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class SystemTray

  1. Object
  2. 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");
        }
    });
}

Methods

public static void setImplementation(CodenameOneImplementation impl)Invoked internally from Display, this method is for internal use only
public static boolean isSupported()True when the platform shows a tray icon.
public static void show(Image icon, String tooltip)Shows the tray icon, or updates it when it is already shown.
public static void hide()Removes the tray icon.
public static boolean isShowing()True while the tray icon is shown.
public static void setTooltip(String tooltip)Changes the tooltip.
public static String getTooltip()The current tooltip.
public static void addMenuItem(String label, ActionListener action)Appends an item to the tray menu.
public static void clearMenu()Removes every menu item.
public static int getMenuItemCount()The number of menu items.
public static void addClickListener(ActionListener l)Adds a listener called on the EDT when the tray icon is clicked.
public static void removeClickListener(ActionListener l)Removes a click listener.
public static void fireClicked()Called by the port on the EDT when the tray icon is clicked.
public static void fireMenuItem(int index)Called by the port on the EDT when a menu item is chosen.

Inherited methods

Method details

setImplementation

public static void setImplementation(CodenameOneImplementation impl)
Invoked internally from Display, this method is for internal use only

Parameters

impl CodenameOneImplementation
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

public static void show(Image icon, String tooltip)
Shows the tray icon, or updates it when it is already shown.

Parameters

icon Image
the icon
tooltip String
the tooltip, may be null

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

public static void setTooltip(String tooltip)
Changes the tooltip.

Parameters

tooltip String
the tooltip, may be null

getTooltip

public static String getTooltip()
The current tooltip.

Returns

the tooltip or null

addMenuItem

public static void addMenuItem(String label, ActionListener action)
Appends an item to the tray menu.

Parameters

label String
the item text
action ActionListener
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

public static void addClickListener(ActionListener l)
Adds a listener called on the EDT when the tray icon is clicked.

Parameters

l ActionListener
the listener

removeClickListener

public static void removeClickListener(ActionListener l)
Removes a click listener.

Parameters

l ActionListener
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 int
the item position, as passed to the port