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

TrayIcon try to dispay a tooltip when is not visible

XMLWordPrintable

    • b79
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-rc-b71)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b71, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux localhost.localdomain 2.6.11-1.1369_FC4 #1 Thu Jun 2 22:55:56 EDT 2005 i686 i686 i386 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      gnome 2.10.0

      A DESCRIPTION OF THE PROBLEM :
      In an ActionListener on the tray icon,
      if i try to remove the tray icon from the system tray i get an
      exception.

      This bug is not a duplicate of 6299866.

      On gnome, when i double-clicked on the tray icon,
      it runs the actionlistener that remove the tray icon but
      because i clicked on the tray icon, it tries to display the
      tooltip.
      I think the tray icon peer doesn't check if its removal
      when it displays the tooltip.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      add an image in the same directory that the class and
      run the class.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      no exception, the tray icon is removed

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
      at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1787)
      at java.awt.Component.getLocationOnScreen(Component.java:1761)
      at sun.awt.X11.XTrayIconPeer.getLocationOnScreen(XTrayIconPeer.java:338)
      at sun.awt.X11.XTrayIconPeer.getBounds(XTrayIconPeer.java:342)
      at sun.awt.X11.XTrayIconPeer.access$200(XTrayIconPeer.java:23)
      at sun.awt.X11.XTrayIconPeer$Tooltip$2$1.run(XTrayIconPeer.java:561)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.awt.X11.XTrayIconPeer$Tooltip$2.run(XTrayIconPeer.java:559)
      at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Created on 12 févr. 2006
       *
       */
      package fr.umlv.ui.desktop;

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

      import javax.swing.ImageIcon;

      public class TrayIconTooltipBug {

        public static void main(String[] args) throws AWTException {
          final SystemTray tray=SystemTray.getSystemTray();
          
          Image camera=new ImageIcon(TrayIconTooltipBug.class.getResource("camera.jpg")).getImage();
          
          PopupMenu popup=new PopupMenu();
          final TrayIcon trayIcon=new TrayIcon(camera,"Snapshot",popup);
          trayIcon.setImageAutoSize(true);
          
          trayIcon.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              tray.remove(trayIcon);
            }
          });
          tray.add(trayIcon);
          
          MenuItem exit=new MenuItem("Exit");
          exit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              System.exit(0);
            }
          });
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      create a thread, wait a time greater than the tooltip time
      (here 3 seconds) ant then remove the tray icon.

      trayIcon.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
              new Thread() {
                @Override public void run() {
                  try {
                    Thread.sleep(3000);
                  } catch (InterruptedException e) {
                    e.printStackTrace();
                  }
                  EventQueue.invokeLater(new Runnable() {
                    public void run() {
                      tray.remove(trayIcon);
                    }
                  });
                }
              }.start();
            }
          });

            dcherepanov Dmitry Cherepanov
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: