Java 1.6 (in beta) finally has a platform-independent System Tray class - java.awt.SystemTray. For more information, see JavaDoc API on http://download.java.net/jdk6/docs/api/java/awt/SystemTray.html.
There is no platform independent solution for placing labels in system tray (in 1.4), but there are several libraries with native components for Linux, Windows and Solaris.
Java Desktop Integration Components (JDIC) is a library of components aimed at integrating Swing with native desktop environments, and is licensed under GPL. Download it from JDic home page. System tray integration component of JDIC is completely usable. Your application does not have to care about the native operating system, and the library works fine with Java Web Start.
This is all that is required to do in order to install an icon into the system tray:
import java.awt.event.*; import javax.swing.*; import org.jdesktop.jdic.tray.*; public class Tray { static SystemTray tray = SystemTray.getDefaultSystemTray(); private Tray(){}; // non-instantiable public static void createTray() { new Thread(new Runnable(){ public void run() { try{Thread.sleep(100);} catch (InterruptedException iex){}; Tray t=new Tray(); t.create(); } }).start(); } private void create(){ JPopupMenu menu; menu = new JPopupMenu("menu title"); ImageIcon icon = getImageIcon(); // load the image icon somehow... TrayIcon ti = new TrayIcon(icon, GUIProperties.getString("menu title"), menu); ti.setIconAutoSize(true); ti.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // icon left click event } }); tray.addTrayIcon(ti); } }
If you plan on using JDic, read the JDIC Disappearing Tray Icon workaround.
For other System Tray integration libraries, see the following sites: