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

JMenuItems in JPopupMenus not receiving ActionEvents - incompat with 1.5

    Details

    • Subcomponent:
    • Introduced In Build:
      b53
    • Introduced In Version:
      7
    • Resolved In Build:
      b02
    • CPU:
      x86
    • OS:
      windows_xp

      Backports

        Description

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

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

        A DESCRIPTION OF THE PROBLEM :
        JMenuItems in JPopupMenus do not seem to be receiving ActionEvents when the mouse button is released over the item. This is incompatible with 1.5.0_10, in which an ActionEvent is received..

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached program. Right or left click in the middle of the frame. Select the item from the popup that appears.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The button text should be displayed in the lower left corner. This is what happens under 1.5.0_10.
        ACTUAL -
        The text is not displayed under 1.6.0.

        Note that if you select the item from the menu in the menu bar, the text is always displayed under both versions. It is only with popups that the anomaly occurs.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.BorderLayout;
        import java.awt.Dimension;
        import java.awt.event.*;

        import javax.swing.JLabel;
        import javax.swing.JMenu;
        import javax.swing.JMenuItem;
        import javax.swing.JMenuBar;
        import javax.swing.JPopupMenu;
        import javax.swing.JPanel;
        import javax.swing.JFrame;

        public class PopupDemo extends JPanel implements ActionListener, MouseListener {
           private static final long serialVersionUID = 1L;
           JPopupMenu popup = new JPopupMenu();
           JLabel messageArea = new JLabel();

           public static void main(String[] args) {
              new PopupDemo();
           }

           public PopupDemo() {
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("menu");
              menuBar.add(menu);
              JMenuItem menuItem = new JMenuItem("menu item");
              menuItem.addActionListener(this);
              menu.add(menuItem);
              
              menuItem = new JMenuItem("popup item");
              menuItem.addActionListener(this);
              popup.add(menuItem);
              
              addMouseListener(this);
              setPreferredSize(new Dimension(200, 200));
              frame.setJMenuBar(menuBar);
              frame.add(this,BorderLayout.CENTER);
              frame.add(messageArea,BorderLayout.SOUTH);
              frame.pack();
              frame.setLocation(200, 200);
              frame.setVisible(true);
           }

           public void actionPerformed(ActionEvent e) {
              messageArea.setText(e.getActionCommand());
           }
           public void mousePressed(MouseEvent e) {
              messageArea.setText("");
              popup.show(this,e.getX(),e.getY());
           }
           public void mouseReleased(MouseEvent e) {
              popup.setVisible(false);
           }
           public void mouseClicked(MouseEvent e) {}
           public void mouseEntered(MouseEvent e) {}
           public void mouseExited(MouseEvent e) {}
        }

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

        Release Regression From : 5
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

        Release Regression From : 5
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: