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

ClassCastException with JPopupMenu attached to TrayIcon

    Details

    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp

      Description

      Run the testcase below,
      you'll see the messageBox and the green trayicon appear

      Click on the green trayIcon ->
      ava.lang.ClassCastException: java.awt.TrayIcon cannot be cast to java.awt.Component
      at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.eventDispatched(BasicPopupMenuUI.java:810)
      at java.awt.Toolkit$SelectiveAWTEventListener.eventDispatched(Toolkit.java:2376)
      etc...

      comes up

      ===Test case===

      OS: Windows XP
      JDK 6,7

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import java.awt.image.BufferedImage;

      public class bug {
          public static void main(String[] args) throws Exception {
              SystemTray tray = SystemTray.getSystemTray();
              TrayIcon ti = new TrayIcon(getImage(), "Hello");
              tray.add(ti);
              
              final JPopupMenu popup = new JPopupMenu("Menu");
              popup.add(new JMenuItem("Item"));
              
              ti.addMouseListener(new MouseAdapter() {
                  public void mouseReleased(MouseEvent e) {
                      popup.setLocation(e.getX(), e.getY());
                      popup.setVisible(true);
                  }
              });
              
              JOptionPane.showMessageDialog(null, "message");
          }

          static Image getImage() {
              BufferedImage im = new BufferedImage(32, 35, BufferedImage.TYPE_INT_ARGB);
              Graphics2D g2 = (Graphics2D) im.getGraphics();
              g2.setColor(Color.GREEN);
              g2.fillRect(0, 0, im.getWidth(), im.getHeight());
              g2.dispose();
              return im;
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alexp Alexander Potochkin (Inactive)
                Reporter:
                alexp Alexander Potochkin (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: