Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

System tray with Swing

Java 1.6 (in beta) finally has a platform-independent System Tray class - java.awt.SystemTray. For more information, see JavaDoc API on

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

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();
    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.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            		// icon left click event

If you plan on using JDic, read the JDIC Disappearing Tray Icon workaround.

Other system tray solutions


Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  howto/system_tray.txt · Last modified: 2006/10/04 19:27 by (gojko)
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: Statistics for project etracker� web controlling instead of log file analysis