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

Regression in selection of JPopupMenu items

XMLWordPrintable

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

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

      A DESCRIPTION OF THE PROBLEM :
      I would like create a JPopupMenu with a single item that will pop up selected and centered under the mouse pointer. I have managed to get the item to pop up centered under the mouse but I the JMenuItem refuses to render as if it is selected. If I move the mouse out of the item and back in it selects properly.

      This seems to be a regression as Java6 update 7 seems to work just fine.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run testcase

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      JMenuItem pops up pre-selected
      ACTUAL -
      JMenuItem renders unselected

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Component;
      import java.awt.Point;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;
      import javax.swing.JFrame;
      import javax.swing.JMenuItem;
      import javax.swing.JPopupMenu;

      public class Test extends JFrame
      {
      public static void main(String[] args)
      {
      JFrame frame = new JFrame();
      frame.setSize(800, 600);
      frame.getContentPane().addMouseListener(new MouseAdapter()
      {
      @Override
      public void mousePressed(MouseEvent e)
      {
      if (e.isPopupTrigger())
      popupTriggered(e);
      }

      @Override
      public void mouseReleased(MouseEvent e)
      {
      if (e.isPopupTrigger())
      popupTriggered(e);
      }

      private void popupTriggered(MouseEvent e)
      {
      JPopupMenu menu = new JPopupMenu();
      final JMenuItem item = new JMenuItem("This is a JMenuItem");
      menu.add(item);
      Point point = e.getPoint();
      int x = point.x - (item.getPreferredSize().width / 2);
      int y = point.y - (item.getPreferredSize().height / 2);
      menu.show((Component) e.getSource(), x, y);
      }
      });
      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      frame.setVisible(true);
      }
      }

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

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

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: