Sunday, April 15, 2007

[Tech] System Trays

In the current Java magazin I've written a short article about System Trays. Do you know what a system tray is? You're right, the nice icons on the rigt bottom side of your task bar (in the case of microsoft windows).

The AWT package of Java 6 already provides all necessery libraries to develop system trays. At present you can also use Java Desktop Integration Components (JDIC) a supported project of Sun. JDIC focus on desktop development, especially Swing.
All necessary components to develop system trays are located in the package org.jdesktop.jdic.tray. The class SystemTray can be seen as placeholder for the TrayIcon. This icon will be displayed in the toolbar and also contains the menu (an instance of JPopupMenu), which will be popuped if the user clicks on the icon. In order to create popup menues with Swing, please look here. Such a popup menu can then be added to the system tray by passing the menu instance to the tray icon.

You can also show messages, like outlook or skype:


The usage of system trays must be carefully planed, because many people don't like unused icons in the toolbar. A system tray can be very usefull in order to provide the user most wanted functions of your system.

2 comments:

Alexander Schatten said...

Does this work platform independent; i.e., does the same code make a system tray icon in windows and also a menu icon on OS X?

Markus Demolsky said...

Thank you for pointing this issue. Yes it does. The JDIC distribution provides necessery libraries for each platform. These libs must be attached to the classpath in order to work correctly.

thanks for the hint agian