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

Modifiers in ActionEvent wrong when ContainerListener is present

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • None
    • 6
    • client-libs
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Modifiers of ActionEvent are wrong if a ContainerListener is present.
      This is because ActionEvent is constructed with modifiers of current event in event queue. Usually it's the MouseEvent, but in case a ContainerListener exists - it's the ContainerEvent!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The following code reproduces it. Notice the modifiers of the ActionEvent are 0 but supposed to be 16.

      import java.awt.Rectangle;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JPopupMenu;
      import javax.swing.JMenuItem;
      import javax.swing.JButton;
      import javax.swing.JDialog;
      import java.awt.event.ContainerListener;
      import java.awt.event.ContainerEvent;

      public class test3 {
          public static void main(String[] args) {
              final JPopupMenu menu = new JPopupMenu();
              JMenuItem item = new JMenuItem("menu item 1");
              item.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          System.out.println("modifiers: " + e.getModifiers());
                      }
                  });
              menu.add(item);

              final JButton btn = new JButton("button 1");
              btn.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          Rectangle r = btn.getBounds();
                          menu.show(btn, r.x, r.y + r.height);
      menu.getParent().addContainerListener(new ContainerListener() {
      public void componentAdded(ContainerEvent e) {
      }

      public void componentRemoved(ContainerEvent e) {
      }

      });
                      }
                  });

              JDialog dlg = new JDialog();
              dlg.getContentPane().add(btn);
              dlg.pack();
              dlg.setVisible(true);
          }

      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the modifiers printing should be 16
      ACTUAL -
      modifiers printing is 0

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Rectangle;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import javax.swing.JPopupMenu;
      import javax.swing.JMenuItem;
      import javax.swing.JButton;
      import javax.swing.JDialog;
      import java.awt.event.ContainerListener;
      import java.awt.event.ContainerEvent;

      public class test3 {
          public static void main(String[] args) {
              final JPopupMenu menu = new JPopupMenu();
              JMenuItem item = new JMenuItem("menu item 1");
              item.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          System.out.println("modifiers: " + e.getModifiers());
                      }
                  });
              menu.add(item);

              final JButton btn = new JButton("button 1");
              btn.addActionListener(new ActionListener() {
                      public void actionPerformed(ActionEvent e) {
                          Rectangle r = btn.getBounds();
                          menu.show(btn, r.x, r.y + r.height);
      menu.getParent().addContainerListener(new ContainerListener() {
      public void componentAdded(ContainerEvent e) {
      }

      public void componentRemoved(ContainerEvent e) {
      }

      });
                      }
                  });

              JDialog dlg = new JDialog();
              dlg.getContentPane().add(btn);
              dlg.pack();
              dlg.setVisible(true);
          }

      }

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

      Attachments

        Issue Links

          Activity

            People

              arapte Ambarish Rapte
              dav Andrei Dmitriev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: