United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4740942 : First MenuItem on JPopupMenu is Highlighted

Details
Type:
Bug
Submit Date:
2002-09-03
Status:
Closed
Updated Date:
2007-07-03
Project Name:
JDK
Resolved Date:
2007-07-03
Component:
client-libs
OS:
windows_nt
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.4.0
Fixed Versions:
7

Related Reports
Duplicate:
Relates:

Sub Tasks

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

Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=13503
                                     
2006-06-08
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
                                     
2006-09-27
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
                                     
2007-07-03



Hardware and Software, Engineered to Work Together