Java Doc for SystemTray.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.awt.SystemTray

SystemTray
public class SystemTray (Code)
The SystemTray class represents the system tray for a desktop. On Microsoft Windows it is referred to as the "Taskbar Status Area", on Gnome it is referred to as the "Notification Area", on KDE it is referred to as the "System Tray". The system tray is shared by all applications running on the desktop.

On some platforms the system tray may not be present or may not be supported, in this case SystemTray.getSystemTray throws UnsupportedOperationException . To detect whether the system tray is supported, use SystemTray.isSupported .

The SystemTray may contain one or more TrayIcon TrayIcons , which are added to the tray using the SystemTray.add method, and removed when no longer needed, using the SystemTray.remove . TrayIcon consists of an image, a popup menu and a set of associated listeners. Please see the TrayIcon class for details.

Every Java application has a single SystemTray instance that allows the app to interface with the system tray of the desktop while the app is running. The SystemTray instance can be obtained from the SystemTray.getSystemTray method. An application may not create its own instance of SystemTray.

The following code snippet demonstrates how to access and customize the system tray:

TrayIcon  trayIcon = null;
 if (SystemTray.isSupported()) {
 // get the SystemTray instance
 SystemTray tray = SystemTray.
SystemTray.getSystemTray ;
 // load an image
java.awt.Image  image = 
java.awt.Toolkit.getImage(String) Toolkit.getDefaultToolkit().getImage (...);
 // create a action listener to listen for default action executed on the tray icon
java.awt.event.ActionListener  listener = new 
java.awt.event.ActionListener ActionListener () {
 public void 
java.awt.event.ActionListener.actionPerformed actionPerformed (
java.awt.event.ActionEvent  e) {
 // execute default action of the application
 // ...
 }
 };
 // create a popup menu
java.awt.PopupMenu  popup = new 
java.awt.PopupMenu.PopupMenu PopupMenu ();
 // create menu item for the default action
 MenuItem defaultItem = new MenuItem(...);
 defaultItem.addActionListener(listener);
 popup.add(defaultItem);
 /// ... add other items
 // construct a TrayIcon
 trayIcon = new 
TrayIcon.TrayIcon(java.awt.ImageStringjava.awt.PopupMenu) TrayIcon (image, "Tray Demo", popup);
 // set the TrayIcon properties
 trayIcon.
TrayIcon.addActionListener(java.awt.event.ActionListener) addActionListener (listener);
 // ...
 // add the tray image
 try {
 tray.
SystemTray.add(TrayIcon) add (trayIcon);
 } catch (AWTException e) {
 System.err.println(e);
 }
 // ...
 } else {
 // disable tray option in your application or
 // perform other actions
 ...
 }
 // ...
 // some time later
 // the application state has changed - update the image
 if (trayIcon != null) {
 trayIcon.
TrayIcon.setImage(java.awt.Image) setImage (updatedImage);
 }
 // ...
 

since:
   1.6
See Also:   TrayIcon
author:
   Bino George
author:
   Denis Mikhalkin
author:
   Sharon Zakhour
author:
   Anton Tarasov




Method Summary
public  voidadd(TrayIcon trayIcon)
     Adds a TrayIcon to the SystemTray. The tray icon becomes visible in the system tray once it is added.
synchronized  voidaddNotify()
    
public synchronized  voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener)
     Adds a PropertyChangeListener to the listener list for a specific property.
static  voidcheckSystemTrayAllowed()
    
public synchronized  PropertyChangeListener[]getPropertyChangeListeners(String propertyName)
     Returns an array of all the listeners that have been associated with the named property.

Only the listeners in this context are returned.

public static  SystemTraygetSystemTray()
     Gets the SystemTray instance that represents the desktop's tray area.
public  DimensiongetTrayIconSize()
     Returns the size, in pixels, of the space that a tray icon will occupy in the system tray.
public  TrayIcon[]getTrayIcons()
     Returns an array of all icons added to the tray by this application.
public static  booleanisSupported()
     Returns whether the system tray is supported on the current platform.
public  voidremove(TrayIcon trayIcon)
     Removes the specified TrayIcon from the SystemTray.
public synchronized  voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener)
     Removes a PropertyChangeListener from the listener list for a specific property.



Method Detail
add
public void add(TrayIcon trayIcon) throws AWTException(Code)
Adds a TrayIcon to the SystemTray. The tray icon becomes visible in the system tray once it is added. The order in which icons are displayed in a tray is not specified - it is platform and implementation-dependent.

All icons added by the application are automatically removed from the SystemTray upon application exit and also when the desktop system tray becomes unavailable.
Parameters:
  trayIcon - the TrayIcon to be added
throws:
  NullPointerException - if trayIcon isnull
throws:
  IllegalArgumentException - if the same instance ofa TrayIcon is added more than once
throws:
  AWTException - if the desktop system tray is missing
See Also:   SystemTray.remove(TrayIcon)
See Also:   SystemTray.getSystemTray
See Also:   TrayIcon
See Also:   java.awt.Image




addNotify
synchronized void addNotify()(Code)



addPropertyChangeListener
public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)
Adds a PropertyChangeListener to the listener list for a specific property. Currently supported property:
  • trayIcons

    This SystemTray 's array of TrayIcon s. The array is accessed via SystemTray.getTrayIcons .
    This property is changed when a TrayIcon is added to (or removed from) the SystemTray .
    For example, this property is changed when the native SystemTray becomes unavailable on the desktop
    and the TrayIcon s are automatically removed.

The listener listens to property changes only in this context.

If listener is null , no exception is thrown and no action is performed.
Parameters:
  propertyName - the specified property
Parameters:
  listener - the property change listener to be added
See Also:   SystemTray.removePropertyChangeListener
See Also:   SystemTray.getPropertyChangeListeners




checkSystemTrayAllowed
static void checkSystemTrayAllowed()(Code)



getPropertyChangeListeners
public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName)(Code)
Returns an array of all the listeners that have been associated with the named property.

Only the listeners in this context are returned.
Parameters:
  propertyName - the specified property all of the PropertyChangeListener s associated withthe named property; if no such listeners have been added orif propertyName is null or invalid, an emptyarray is returned
See Also:   SystemTray.addPropertyChangeListener
See Also:   SystemTray.removePropertyChangeListener




getSystemTray
public static SystemTray getSystemTray()(Code)
Gets the SystemTray instance that represents the desktop's tray area. This always returns the same instance per application. On some platforms the system tray may not be supported. You may use the SystemTray.isSupported method to check if the system tray is supported.

If a SecurityManager is installed, the AWTPermission accessSystemTray must be granted in order to get the SystemTray instance. Otherwise this method will throw a SecurityException. the SystemTray instance that representsthe desktop's tray area
throws:
  UnsupportedOperationException - if the system tray isn'tsupported by the current platform
throws:
  HeadlessException - ifGraphicsEnvironment.isHeadless() returns true
throws:
  SecurityException - if accessSystemTray permissionis not granted
See Also:   SystemTray.add(TrayIcon)
See Also:   TrayIcon
See Also:   SystemTray.isSupported
See Also:   SecurityManager.checkPermission
See Also:   AWTPermission




getTrayIconSize
public Dimension getTrayIconSize()(Code)
Returns the size, in pixels, of the space that a tray icon will occupy in the system tray. Developers may use this methods to acquire the preferred size for the image property of a tray icon before it is created. For convenience, there is a similar method TrayIcon.getSize in the TrayIcon class. the default size of a tray icon, in pixels
See Also:   TrayIcon.setImageAutoSize(boolean)
See Also:   java.awt.Image
See Also:   TrayIcon.getSize



getTrayIcons
public TrayIcon[] getTrayIcons()(Code)
Returns an array of all icons added to the tray by this application. You can't access the icons added by another application. Some browsers partition applets in different code bases into separate contexts, and establish walls between these contexts. In such a scenario, only the tray icons added from this context will be returned.

The returned array is a copy of the actual array and may be modified in any way without affecting the system tray. To remove a TrayIcon from the SystemTray, use the SystemTray.remove(TrayIcon) method. an array of all tray icons added to this tray, or anempty array if none has been added
See Also:   SystemTray.add(TrayIcon)
See Also:   TrayIcon




isSupported
public static boolean isSupported()(Code)
Returns whether the system tray is supported on the current platform. In addition to displaying the tray icon, minimal system tray support includes either a popup menu (see TrayIcon.setPopupMenu(PopupMenu) ) or an action event (see TrayIcon.addActionListener(ActionListener) ).

Developers should not assume that all of the system tray functionality is supported. To guarantee that the tray icon's default action is always accessible, add the default action to both the action listener and the popup menu. See the SystemTray example for an example of how to do this.

Note: When implementing SystemTray and TrayIcon it is strongly recommended that you assign different gestures to the popup menu and an action event. Overloading a gesture for both purposes is confusing and may prevent the user from accessing one or the other.
See Also:   SystemTray.getSystemTray
See Also:    false if no system tray access is supported; thismethod returns true if the minimal system tray access issupported but does not guarantee that all system trayfunctionality is supported for the current platform




remove
public void remove(TrayIcon trayIcon)(Code)
Removes the specified TrayIcon from the SystemTray.

All icons added by the application are automatically removed from the SystemTray upon application exit and also when the desktop system tray becomes unavailable.

If trayIcon is null or was not added to the system tray, no exception is thrown and no action is performed.
Parameters:
  trayIcon - the TrayIcon to be removed
See Also:   SystemTray.add(TrayIcon)
See Also:   TrayIcon




removePropertyChangeListener
public synchronized void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)(Code)
Removes a PropertyChangeListener from the listener list for a specific property.

The PropertyChangeListener must be from this context.

If propertyName or listener is null or invalid, no exception is thrown and no action is taken.
Parameters:
  propertyName - the specified property
Parameters:
  listener - the PropertyChangeListener to be removed
See Also:   SystemTray.addPropertyChangeListener
See Also:   SystemTray.getPropertyChangeListeners




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.