Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4740942
Votes 5
Synopsis First MenuItem on JPopupMenu is Highlighted
Category java:classes_swing
Reported Against 1.4
Release Fixed
State 11-Closed, duplicate of 6217905, bug
Priority: 4-Low
Related Bugs 6652158
Submit Date 03-SEP-2002
Description


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)

 customer  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) 
======================================================================
Posted Date : 2005-09-26 15:15:03.0
Work Around
N/A
Evaluation
Contribution forum : https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=13503
Posted Date : 2006-06-08 21:12:56.0

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
Posted Date : 2006-09-27 13:07:10.0

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
Posted Date : 2007-07-03 17:55:14.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang