TrayIcon
object represents a tray icon that can be
added to the system tray
. A
TrayIcon
can have a tooltip (text), an image, a popup
menu, and a set of listeners associated with it.
A TrayIcon
can generate various MouseEvents
and supports adding corresponding listeners to receive
notification of these events. TrayIcon
processes some
of the events by itself. For example, by default, when the
right-mouse click is performed on the TrayIcon
it
displays the specified popup menu. When the mouse hovers
over the TrayIcon
the tooltip is displayed (this behaviour is
platform dependent).
Note
When the MouseEvent
is
dispatched to its registered listeners its component
property will be set to null
. (See java.
) The
source
property will be set to this
TrayIcon
. (See java.
)
Note
A well-behaved TrayIcon
implementation
will assign different gestures to showing a popup menu and
selecting a tray icon.
A TrayIcon
can generate an ActionEvent
. On some platforms, this occurs when the user selects
the tray icon using either the mouse or keyboard.
If a SecurityManager is installed, the AWTPermission
accessSystemTray
must be granted in order to create
a TrayIcon
. Otherwise the constructor will throw a
SecurityException.
See the SystemTray
class overview for an example on how
to use the TrayIcon
API.
Implementation Note
When the apple.awt.enableTemplateImages
property is
set, all images associated with instances of this class are treated
as template images by the native desktop system. This means all color
information is discarded, and the image is adapted automatically to
be visible when desktop theme and/or colors change. This property
only affects MacOSX.
SystemTray#add
, java.awt.event.ComponentEvent#getComponent
, java.util.EventObject#getSource
Modifier and Type | Class and Description |
---|---|
public static enum | TrayIcon.
The message type determines which icon will be displayed in the caption of the message, and a possible system sound a message may generate upon showing. |
Modifier and Type | Field and Description |
---|---|
private final AccessControlContext | acc
Deprecated
as a consequence of
AccessControlContext being deprecated.
|
private String | |
pack-priv transient ActionListener | |
private boolean | |
private int | |
private Image | |
pack-priv transient MouseListener | |
pack-priv transient MouseMotionListener | |
private transient TrayIconPeer | |
private PopupMenu | |
private String |
Access | Constructor and Description |
---|---|
private | |
public | |
public | |
public | TrayIcon(Image
the image, String Image to be usedthe string to be used as tooltip text; if the
value is tooltip, PopupMenu null no tooltip is shownthe menu to be used for the tray icon's popup
menu; if the value is popup)null no popup menu is shownCreates a |
Modifier and Type | Method and Description |
---|---|
public synchronized void | addActionListener(ActionListener
the action listener listener)Adds the specified action listener to receive
|
public synchronized void | addMouseListener(MouseListener
the mouse listener listener)Adds the specified mouse listener to receive mouse events from
this |
public synchronized void | addMouseMotionListener(MouseMotionListener
the mouse listener listener)Adds the specified mouse listener to receive mouse-motion
events from this |
pack-priv void | |
pack-priv void | |
public void | displayMessage(String
the caption displayed above the text, usually in
bold; may be caption, String null the text displayed for the particular message; may be
text, TrayIcon.null an enum indicating the message type messageTypeDisplays a popup message near the tray icon. |
pack-priv final AccessControlContext | |
public String | Returns: the action command name, ornull if none existsReturns the command name of the action event fired by this tray icon. |
public synchronized ActionListener[] | Returns: all of theActionListeners registered on
this TrayIcon or an empty array if no action
listeners are currently registeredReturns an array of all the action listeners
registered on this |
pack-priv int | |
public Image | |
public synchronized MouseListener[] | Returns: all of theMouseListeners registered on
this TrayIcon or an empty array if no mouse
listeners are currently registeredReturns an array of all the mouse listeners
registered on this |
public synchronized MouseMotionListener[] | Returns: all of theMouseInputListeners registered on
this TrayIcon or an empty array if no mouse
listeners are currently registeredReturns an array of all the mouse-motion listeners
registered on this |
public PopupMenu | Returns: the popup menu ornull if none existsReturns the popup menu associated with this |
public Dimension | Returns: the size of the tray icon, in pixelsReturns the size, in pixels, of the space that the tray icon occupies in the system tray. |
public String | Returns: the tooltip string ornull if none existsReturns the tooltip string associated with this
|
private static native void | |
public boolean | Returns: true if the image will be auto-sized,
false otherwiseReturns the value of the auto-size property. |
pack-priv void | |
pack-priv void | |
pack-priv void | |
pack-priv void | |
public synchronized void | removeActionListener(ActionListener
the action listener listener)Removes the specified action listener. |
public synchronized void | |
public synchronized void | removeMouseMotionListener(MouseMotionListener
the mouse listener listener)Removes the specified mouse-motion listener. |
pack-priv void | |
public void | setActionCommand(String
a string used to set the tray icon's
action command. command)Sets the command name for the action event fired by this tray icon. |
pack-priv void | |
public void | |
public void | setImageAutoSize(boolean
true to auto-size the image,
false otherwiseSets the auto-size property. |
public void | setPopupMenu(PopupMenu
a popup)PopupMenu or null to
remove any popup menuSets the popup menu for this |
public void | setToolTip(String
the string for the tooltip; if the value is
tooltip)null no tooltip is shownSets the tooltip string for this |
acc | back to summary |
---|---|
private final AccessControlContext acc
Deprecated as a consequence of
|
actionCommand | back to summary |
---|---|
private String actionCommand |
actionListener | back to summary |
---|---|
pack-priv transient ActionListener actionListener |
autosize | back to summary |
---|---|
private boolean autosize |
id | back to summary |
---|---|
private int id |
image | back to summary |
---|---|
private Image image |
mouseListener | back to summary |
---|---|
pack-priv transient MouseListener mouseListener |
mouseMotionListener | back to summary |
---|---|
pack-priv transient MouseMotionListener mouseMotionListener |
peer | back to summary |
---|---|
private transient TrayIconPeer peer |
popup | back to summary |
---|---|
private PopupMenu popup |
tooltip | back to summary |
---|---|
private String tooltip |
TrayIcon | back to summary |
---|---|
private TrayIcon() throws UnsupportedOperationException, HeadlessException, SecurityException |
TrayIcon | back to summary |
---|---|
public TrayIcon(Image image) Creates a
|
TrayIcon | back to summary |
---|---|
public TrayIcon(Image image, String tooltip) Creates a
|
TrayIcon | back to summary |
---|---|
public TrayIcon(Image image, String tooltip, PopupMenu popup) Creates a
|
addActionListener | back to summary |
---|---|
public synchronized void addActionListener(ActionListener listener) Adds the specified action listener to receive
Calling this method with a Refer to AWT Threading Issues for details on AWT's threading model.
|
addMouseListener | back to summary |
---|---|
public synchronized void addMouseListener(MouseListener listener) Adds the specified mouse listener to receive mouse events from
this Note The Note The Refer to AWT Threading Issues for details on AWT's threading model.
|
addMouseMotionListener | back to summary |
---|---|
public synchronized void addMouseMotionListener(MouseMotionListener listener) Adds the specified mouse listener to receive mouse-motion
events from this Note The Note The Refer to AWT Threading Issues for details on AWT's threading model.
|
addNotify | back to summary |
---|---|
pack-priv void addNotify() throws AWTException |
dispatchEvent | back to summary |
---|---|
pack-priv void dispatchEvent(AWTEvent e) |
displayMessage | back to summary |
---|---|
public void displayMessage(String caption, String text, TrayIcon. Displays a popup message near the tray icon. The message will
disappear after a time or if the user clicks on it. Clicking
on the message may trigger an Either the caption or the text may be Note Some platforms may not support showing a message.
|
getAccessControlContext | back to summary |
---|---|
pack-priv final AccessControlContext getAccessControlContext()
Deprecated as a consequence of
|
getActionCommand | back to summary |
---|---|
public String getActionCommand() Returns the command name of the action event fired by this tray icon.
|
getActionListeners | back to summary |
---|---|
public synchronized ActionListener[] getActionListeners() Returns an array of all the action listeners
registered on this
|
getID | back to summary |
---|---|
pack-priv int getID() |
getImage | back to summary |
---|---|
public Image getImage() Returns the current image used for this
|
getMouseListeners | back to summary |
---|---|
public synchronized MouseListener[] getMouseListeners() Returns an array of all the mouse listeners
registered on this
|
getMouseMotionListeners | back to summary |
---|---|
public synchronized MouseMotionListener[] getMouseMotionListeners() Returns an array of all the mouse-motion listeners
registered on this
|
getPopupMenu | back to summary |
---|---|
public PopupMenu getPopupMenu() Returns the popup menu associated with this
|
getSize | back to summary |
---|---|
public Dimension getSize() Returns the size, in pixels, of the space that the tray icon
occupies in the system tray. For the tray icon that is not yet
added to the system tray, the returned size is equal to the
result of the
|
getToolTip | back to summary |
---|---|
public String getToolTip() Returns the tooltip string associated with this
|
initIDs | back to summary |
---|---|
private static native void initIDs() |
isImageAutoSize | back to summary |
---|---|
public boolean isImageAutoSize() Returns the value of the auto-size property.
|
processActionEvent | back to summary |
---|---|
pack-priv void processActionEvent(ActionEvent e) |
processEvent | back to summary |
---|---|
pack-priv void processEvent(AWTEvent e) |
processMouseEvent | back to summary |
---|---|
pack-priv void processMouseEvent(MouseEvent e) |
processMouseMotionEvent | back to summary |
---|---|
pack-priv void processMouseMotionEvent(MouseEvent e) |
removeActionListener | back to summary |
---|---|
public synchronized void removeActionListener(ActionListener listener) Removes the specified action listener. Calling this method with
Refer to AWT Threading Issues for details on AWT's threading model.
|
removeMouseListener | back to summary |
---|---|
public synchronized void removeMouseListener(MouseListener listener) Removes the specified mouse listener. Calling this method with
Refer to AWT Threading Issues for details on AWT's threading model.
|
removeMouseMotionListener | back to summary |
---|---|
public synchronized void removeMouseMotionListener(MouseMotionListener listener) Removes the specified mouse-motion listener. Calling this method with
Refer to AWT Threading Issues for details on AWT's threading model.
|
removeNotify | back to summary |
---|---|
pack-priv void removeNotify() |
setActionCommand | back to summary |
---|---|
public void setActionCommand(String command) Sets the command name for the action event fired by this tray
icon. By default, this action command is set to
|
setID | back to summary |
---|---|
pack-priv void setID(int id) |
setImage | back to summary |
---|---|
public void setImage(Image image) Sets the image for this If the image represents an animated image, it will be animated automatically. See the Calling this method with the same image that is currently being used has no effect.
|
setImageAutoSize | back to summary |
---|---|
public void setImageAutoSize(boolean autosize) Sets the auto-size property. Auto-size determines whether the
tray image is automatically sized to fit the space allocated
for the image on the tray. By default, the auto-size property
is set to If auto-size is If auto-size is
|
setPopupMenu | back to summary |
---|---|
public void setPopupMenu(PopupMenu popup) Sets the popup menu for this Note that this The Note Some platforms may not support showing the user-specified popup menu component when the user right-clicks the tray icon. In this situation, either no menu will be displayed or, on some systems, a native version of the menu may be displayed.
|
setToolTip | back to summary |
---|---|
public void setToolTip(String tooltip) Sets the tooltip string for this
|
TrayIcon
, TrayIcon#displayMessage(String, String, MessageType)
Modifier and Type | Field and Description |
---|---|
public static final TrayIcon. | ERROR
An error message |
public static final TrayIcon. | INFO
An information message |
public static final TrayIcon. | NONE
Simple message |
public static final TrayIcon. | WARNING
A warning message |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public static TrayIcon. | |
public static TrayIcon. |
ERROR | back to summary |
---|---|
public static final TrayIcon. An error message |
INFO | back to summary |
---|---|
public static final TrayIcon. An information message |
NONE | back to summary |
---|---|
public static final TrayIcon. Simple message |
WARNING | back to summary |
---|---|
public static final TrayIcon. A warning message |
MessageType | back to summary |
---|---|
private MessageType() |
valueOf | back to summary |
---|---|
public static TrayIcon. |
values | back to summary |
---|---|
public static TrayIcon. |