Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6575110

Throws AWTException if add system tray on Gnome Desktop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 6u2
    • client-libs
    • x86, sparc
    • linux, solaris_2.5.1

      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();
          }
          
      }

            Unassigned Unassigned
            elarsen Erik Larsen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: