Methods Summary |
---|
public synchronized void | addActionListener(java.awt.event.ActionListener listener)Adds the specified action listener to receive
ActionEvent s from this TrayIcon .
Action events usually occur when a user selects the tray icon,
using either the mouse or keyboard. The conditions in which
action events are generated are platform-dependent.
Calling this method with a null value has no
effect.
Refer to AWT Threading Issues for details on AWT's threading model.
if (listener == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, listener);
|
public synchronized void | addMouseListener(java.awt.event.MouseListener listener)Adds the specified mouse listener to receive mouse events from
this TrayIcon . Calling this method with a
null value has no effect.
Note: The {@code MouseEvent}'s coordinates (received
from the {@code TrayIcon}) are relative to the screen, not the
{@code TrayIcon}.
Note: The MOUSE_ENTERED and
MOUSE_EXITED mouse events are not supported.
Refer to AWT Threading Issues for details on AWT's threading model.
if (listener == null) {
return;
}
mouseListener = AWTEventMulticaster.add(mouseListener, listener);
|
public synchronized void | addMouseMotionListener(java.awt.event.MouseMotionListener listener)Adds the specified mouse listener to receive mouse-motion
events from this TrayIcon . Calling this method
with a null value has no effect.
Note: The {@code MouseEvent}'s coordinates (received
from the {@code TrayIcon}) are relative to the screen, not the
{@code TrayIcon}.
Note: The MOUSE_DRAGGED mouse event is not supported.
Refer to AWT Threading Issues for details on AWT's threading model.
if (listener == null) {
return;
}
mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, listener);
|
void | addNotify()
synchronized (this) {
if (peer == null) {
peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createTrayIcon(this);
}
}
peer.setToolTip(tooltip);
|
void | dispatchEvent(java.awt.AWTEvent e)
EventQueue.setCurrentEventAndMostRecentTime(e);
Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
processEvent(e);
|
public void | displayMessage(java.lang.String caption, java.lang.String text, java.awt.TrayIcon$MessageType messageType)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 {@code ActionEvent}.
Either the caption or the text may be null , but an
NullPointerException is thrown if both are
null .
When displayed, the caption or text strings may be truncated on
some platforms; the number of characters that may be displayed is
platform-dependent.
Note: Some platforms may not support
showing a message.
if (caption == null && text == null) {
throw new NullPointerException("displaying the message with both caption and text being null");
}
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.displayMessage(caption, text, messageType.toString());
}
|
public java.lang.String | getActionCommand()Returns the command name of the action event fired by this tray icon.
return actionCommand;
|
public synchronized java.awt.event.ActionListener[] | getActionListeners()Returns an array of all the action listeners
registered on this TrayIcon .
return (ActionListener[])(getListeners(ActionListener.class));
|
int | getID()
return id;
|
public java.awt.Image | getImage()Returns the current image used for this TrayIcon .
return image;
|
T[] | getListeners(java.lang.Class listenerType)
EventListener l = null;
if (listenerType == MouseListener.class) {
l = mouseListener;
} else if (listenerType == MouseMotionListener.class) {
l = mouseMotionListener;
} else if (listenerType == ActionListener.class) {
l = actionListener;
}
return AWTEventMulticaster.getListeners(l, listenerType);
|
public synchronized java.awt.event.MouseListener[] | getMouseListeners()Returns an array of all the mouse listeners
registered on this TrayIcon .
return (MouseListener[])(getListeners(MouseListener.class));
|
public synchronized java.awt.event.MouseMotionListener[] | getMouseMotionListeners()Returns an array of all the mouse-motion listeners
registered on this TrayIcon .
return (MouseMotionListener[]) (getListeners(MouseMotionListener.class));
|
public java.awt.PopupMenu | getPopupMenu()Returns the popup menu associated with this TrayIcon .
return popup;
|
public java.awt.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 {@link SystemTray#getTrayIconSize}.
return SystemTray.getSystemTray().getTrayIconSize();
|
public java.lang.String | getToolTip()Returns the tooltip string associated with this
TrayIcon .
return tooltip;
|
private static native void | initIDs()
|
public boolean | isImageAutoSize()Returns the value of the auto-size property.
return autosize;
|
void | processActionEvent(java.awt.event.ActionEvent e)
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(e);
}
|
void | processEvent(java.awt.AWTEvent e)
if (e instanceof MouseEvent) {
switch(e.getID()) {
case MouseEvent.MOUSE_PRESSED:
case MouseEvent.MOUSE_RELEASED:
case MouseEvent.MOUSE_CLICKED:
processMouseEvent((MouseEvent)e);
break;
case MouseEvent.MOUSE_MOVED:
processMouseMotionEvent((MouseEvent)e);
break;
default:
return;
}
} else if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
}
|
void | processMouseEvent(java.awt.event.MouseEvent e)
MouseListener listener = mouseListener;
TrayIconPeer peer = this.peer;
if (e.isPopupTrigger() && peer != null) {
peer.showPopupMenu(e.getPoint().x, e.getPoint().y);
}
if (listener != null) {
int id = e.getID();
switch(id) {
case MouseEvent.MOUSE_PRESSED:
listener.mousePressed(e);
break;
case MouseEvent.MOUSE_RELEASED:
listener.mouseReleased(e);
break;
case MouseEvent.MOUSE_CLICKED:
listener.mouseClicked(e);
break;
default:
return;
}
}
|
void | processMouseMotionEvent(java.awt.event.MouseEvent e)
MouseMotionListener listener = mouseMotionListener;
if (listener != null &&
e.getID() == MouseEvent.MOUSE_MOVED)
{
listener.mouseMoved(e);
}
|
public synchronized void | removeActionListener(java.awt.event.ActionListener listener)Removes the specified action listener. Calling this method with
null or an invalid value has no effect.
Refer to AWT Threading Issues for details on AWT's threading model.
if (listener == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, listener);
|
public synchronized void | removeMouseListener(java.awt.event.MouseListener listener)Removes the specified mouse listener. Calling this method with
null or an invalid value has no effect.
Refer to AWT Threading Issues for details on AWT's threading model.
if (listener == null) {
return;
}
mouseListener = AWTEventMulticaster.remove(mouseListener, listener);
|
public synchronized void | removeMouseMotionListener(java.awt.event.MouseMotionListener listener)Removes the specified mouse-motion listener. Calling this method with
null or an invalid value has no effect.
Refer to AWT Threading Issues for details on AWT's threading model.
if (listener == null) {
return;
}
mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, listener);
|
void | removeNotify()
TrayIconPeer p = null;
synchronized (this) {
p = peer;
peer = null;
}
if (p != null) {
p.dispose();
}
|
public void | setActionCommand(java.lang.String command)Sets the command name for the action event fired by this tray
icon. By default, this action command is set to
null .
actionCommand = command;
|
void | setID(int id)
this.id = id;
|
public void | setImage(java.awt.Image image)Sets the image for this TrayIcon . The previous
tray icon image is discarded without calling the {@link
java.awt.Image#flush} method you will need to call it
manually.
If the image represents an animated image, it will be
animated automatically.
See the {@link #setImageAutoSize(boolean)} property for
details on the size of the displayed image.
Calling this method with the same image that is currently
being used has no effect.
if (image == null) {
throw new NullPointerException("setting null Image");
}
this.image = image;
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.updateImage();
}
|
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 false .
If auto-size is false , and the image size
doesn't match the tray icon space, the image is painted as-is
inside that space if larger than the allocated space, it will
be cropped.
If auto-size is true , the image is stretched or shrunk to
fit the tray icon space.
this.autosize = autosize;
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.updateImage();
}
|
public void | setPopupMenu(java.awt.PopupMenu popup)Sets the popup menu for this TrayIcon . If
popup is null , no popup menu will be
associated with this TrayIcon .
Note that this popup must not be added to any
parent before or after it is set on the tray icon. If you add
it to some parent, the popup may be removed from
that parent.
The {@code popup} can be set on one {@code TrayIcon} only.
Setting the same popup on multiple {@code TrayIcon}s will cause
an {@code IllegalArgumentException}.
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.
if (popup == this.popup) {
return;
}
synchronized (TrayIcon.class) {
if (popup != null) {
if (popup.isTrayIconPopup) {
throw new IllegalArgumentException("the PopupMenu is already set for another TrayIcon");
}
popup.isTrayIconPopup = true;
}
if (this.popup != null) {
this.popup.isTrayIconPopup = false;
}
this.popup = popup;
}
|
public void | setToolTip(java.lang.String tooltip)Sets the tooltip string for this TrayIcon . The
tooltip is displayed automatically when the mouse hovers over
the icon. Setting the tooltip to null removes any
tooltip text.
When displayed, the tooltip string may be truncated on some platforms;
the number of characters that may be displayed is platform-dependent.
this.tooltip = tooltip;
TrayIconPeer peer = this.peer;
if (peer != null) {
peer.setToolTip(tooltip);
}
|