Create Tray Icon : TrayIcon « JDK 6 « Java

Create Tray Icon


import java.awt.AWTException;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Test {
  static Image image = Toolkit.getDefaultToolkit().getImage("images/tray.gif");

  static TrayIcon trayIcon = new TrayIcon(image, "Tester2");

  public static void main(String[] a) throws Exception {
    if (SystemTray.isSupported()) {
      SystemTray tray = SystemTray.getSystemTray();

      trayIcon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          System.out.println("In here");
          trayIcon.displayMessage("Tester!", "Some action performed", TrayIcon.MessageType.INFO);

      try {
      } catch (AWTException e) {
        System.err.println("TrayIcon could not be added.");


Related examples in the same category

1.Remove Icon from TrayIcon
2.Add mouse listener to TrayIcon
3.Add Mouse motion listener to TrayIcon
4.Using system tray
5.Demonstrating a System Tray That Responds to Selection
6.Add PropertyChangeListener to TrayIcon
7.Have a systray icon (Windows)
8.System tray icon
9.This program demonstrates the system tray API.