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

First MenuItem on JPopupMenu is Highlighted

XMLWordPrintable

      Name: jk109818 Date: 09/03/2002


      FULL PRODUCT VERSION :
      java version "1.4.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

      AND

      java version "1.4.1-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
      Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)

      Microsoft Windows XP [Version 5.1.2600]


      A DESCRIPTION OF THE PROBLEM :
      The first menu item in a popup menu should not be
      automatically highlighted.

      In Java when a popup menu is shown, the first menuitem is
      highlighted regardless of where the mouse is.

      In Windows this is not the case. Rightmouse click on the
      windows desktop and you will see the first menu item is not
      selected.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected -> First menuitem is not highlighed
      Acutal -> First menuitem is hightlighted

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

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

      public class Test {

          static JPopupMenu p = new JPopupMenu("test");

          public static void main(String[] args) {

          try {
       UIManager.setLookandFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              }
              catch (Exception e) {

                  System.exit(-1);
              }

              JFrame f = new JFrame();
              f.addMouseListener(new PopupListener(p, f));
              f.setSize(100, 100);
              f.getContentPane().setLayout(new FlowLayout());

              JMenuItem b = new JMenuItem("B");
              JMenuItem c = new JMenuItem("C");

              p.add(b);
              p.add(c);

              f.setVisible(true);

          }

          static class PopupListener extends MouseAdapter {
              private JPopupMenu _menu;
              private Component _invoker;

              public PopupListener(JPopupMenu menu) {
                  _menu = menu;

              }

              public PopupListener(JPopupMenu menu, Component invoker) {
                  _menu = menu;

                  _invoker = invoker;
              }

              public void mousePressed(MouseEvent e) {
                  maybeShowPopup(e);
              }

              public void mouseReleased(MouseEvent e) {
                  maybeShowPopup(e);
              }

              private void maybeShowPopup(MouseEvent e) {
                  if (e.isPopupTrigger()) {
                      _menu.show(_invoker, e.getX() + 2, e.getY() + 2);
                  }
              }
          }


      }


      ---------- END SOURCE ----------
      (Review ID: 163895)
      ======================================================================

            alexp Alexander Potochkin (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: