JDK-4740942 : First MenuItem on JPopupMenu is Highlighted
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-09-03
  • Updated: 2007-07-03
  • Resolved: 2007-07-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Description
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) 
======================================================================

Comments
EVALUATION This bug is tightly bound with #6217905 It doesn't make sence to fix it separately so I closed it as duplicate Fix for #6217905 will solve this problem as well
03-07-2007

EVALUATION The peabody fix is good, but it has a problem: when popup is shown it is impossible to select an item with help of the keyboard arrow buttons The native popups works this way: it is unselected when it's shown up but the first item becomes selected if you press down arrow button
27-09-2006

EVALUATION Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=13503
08-06-2006