Class SystemTray

java.lang.Object
com.codename1.desktop.SystemTray

public final class SystemTray extends Object

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

      public static void show(Image icon, String tooltip)

      Shows the tray icon, or updates it when it is already shown.

      Parameters
      • icon: the icon
      • tooltip: 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: 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: the item text
      • action: 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: the listener
    • removeClickListener

      public static void removeClickListener(ActionListener l)

      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