Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class SystemTray
- Object
- 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
Inherited methods
Method details
setImplementation
public static void setImplementation(CodenameOneImplementation impl)Invoked internally from Display, this method is for internal use only
Parameters
implCodenameOneImplementation- 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
iconImage- the icon
tooltipString- 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
tooltipString- 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
labelString- the item text
actionActionListener- 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
lActionListener- the listener
removeClickListener
public static void removeClickListener(ActionListener l)Removes a click listener.
Parameters
lActionListener- 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
indexint- the item position, as passed to the port