JDK-6575110 : Throws AWTException if add system tray on Gnome Desktop
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u2
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux,solaris_2.5.1
  • CPU: x86,sparc
  • Submitted: 2007-06-28
  • Updated: 2010-04-02
  • Resolved: 2007-07-31
Related Reports
Duplicate :  
Relates :  
Description
OPERATING SYSTEM(S):
--------------------
Red Hat Enterprise Linux Server release 5 

FULL JDK VERSION(S):
-------------------
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_02-b05, mixed mode)

DESCRIPTION:
------------
Abstract: Throws AWTException if add system tray on SLES9 Gnome Desktop.

How to reproduce the problem:
1. Login SLES9 wiht Gnome Desktop 
2. Run test case: "java SystemTrayTest".
   <--PROBLEM: Print out exception:
         image sun.awt.image.ToolkitImage@6b4da8f4
TrayIcon could not be added.
	java.awt.AWTException: TrayIcon couldn't be displayed.
        at sun.awt.X11.XSystemTrayPeer.addTrayIcon(XSystemTrayPeer.java:54)
        at sun.awt.X11.XTrayIconPeer.<init>(XTrayIconPeer.java:179)
        at sun.awt.X11.XToolkit.createTrayIcon(XToolkit.java:849)
        at java.awt.TrayIcon.addNotify(TrayIcon.java:662)
        at java.awt.SystemTray.add(SystemTray.java:240)
        at SystemTrayTest.<init>(SystemTrayTest.java:69)
        at SystemTrayTest.main(SystemTrayTest.java:85)


TestCase:

import java.awt.*;
import java.awt.event.*;

public class SystemTrayTest
{
    
    public SystemTrayTest()
    {
        
        final TrayIcon trayIcon;

        if (SystemTray.isSupported()) {

            SystemTray tray = SystemTray.getSystemTray();
            Image image = Toolkit.getDefaultToolkit().getImage("tray.gif");

            MouseListener mouseListener = new MouseListener() {
                
                public void mouseClicked(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse clicked!");                 
                }
                public void mouseEntered(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse entered!");                 
                }
                public void mouseExited(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse exited!");                 
                }
                public void mousePressed(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse pressed!");                 
                }
                public void mouseReleased(MouseEvent e) {
                    System.out.println("Tray Icon - Mouse released!");                 
                }

            };

            ActionListener exitListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    System.out.println("Exiting...");
                    System.exit(0);
                }
            };
            
            PopupMenu popup = new PopupMenu();
            MenuItem defaultItem = new MenuItem("Exit");
            defaultItem.addActionListener(exitListener);
            popup.add(defaultItem);

            trayIcon = new TrayIcon(image, "Tray Demo", popup);

            ActionListener actionListener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    trayIcon.displayMessage("Action Event", 
                        "An Action Event Has Been Peformed!",
                        TrayIcon.MessageType.INFO);
                }
            };
            
            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(actionListener);
            trayIcon.addMouseListener(mouseListener);

            //    Depending on which Mustang build you have, you may need to uncomment
            //    out the following code to check for an AWTException when you add 
            //    an image to the system tray.

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

        } else {
            System.err.println("System tray is currently not supported.");
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        SystemTrayTest main = new SystemTrayTest();
    }
    
}

Comments
EVALUATION Submitter has confirmed this problem is only reproduced when GNOME notification area is absent (it seems it is by default on some systems like SLES 9). So the bug is that SystemTray.isSupported() must return 'false' in this situation or, even better, the notions of 'supported' and 'available' for SystemTray should be different. See 6438179 for more details.
31-07-2007

WORK AROUND None
28-06-2007