United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6217905 JPopupMenu keyboard navigation stops working
JDK-6217905 : JPopupMenu keyboard navigation stops working

Details
Type:
Bug
Submit Date:
2005-01-14
Status:
Closed
Updated Date:
2013-07-09
Project Name:
JDK
Resolved Date:
2011-05-17
Component:
client-libs
OS:
windows_nt,windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0,5.0
Fixed Versions:

Related Reports
Backport:
Duplicate:
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

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

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

A DESCRIPTION OF THE PROBLEM :
Run the testcase, scroll the mouse over choice 1, choice 2, choice 3 then continue vertically until the JMenuPopup has no entry selected. Now try using the keyboard arrow keys to change the menu selection. This will fail.

You can experiment and you will notice that keyboard navigation works properly until the mouse causes the JPopupMenu selection to clear (i.e. no entry selected). There is no way to bring back keyboard navigation without using the mouse.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It should be possible to bring back menu focus, selection by using the keyboard. Use notification-area popups as an example of how this should work.

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class Test
{
  public static void main(String[] args)
  {
    JFrame invoker = new JFrame();
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem("choice 1");
    ActionListener actionListener = new ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        JMenuItem menuItem = (JMenuItem) e.getSource();
        System.out.println(menuItem.getText());
      }
    };
    menuItem.addActionListener(actionListener);
    popupMenu.add(menuItem);
    menuItem = new JMenuItem("choice 2");
    menuItem.addActionListener(actionListener);
    popupMenu.add(menuItem);
    menuItem = new JMenuItem("choice 3");
    menuItem.addActionListener(actionListener);
    popupMenu.add(menuItem);
    invoker.setUndecorated(true);
    invoker.setSize(popupMenu.getPreferredSize());
    invoker.setVisible(true);
    
    popupMenu.show(invoker, 0, 0);
  }
}
---------- END SOURCE ----------
###@###.### 2005-1-14 23:35:49 GMT

                                    

Comments
EVALUATION

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

This bug is tightly coupled with the bug #4740942
so the the fix will solve both problems

First - we should not select the fist item in popups by default
(see #4740942 for details)
Windows and GTK don't do that
commercial java applications like Idea 
fixes this bug by themselves and doesn't automatically 
select the first item for popups as well, neither does Mozilla applications
the only GUI toolkit which behaves differently is Motif

I believe that we should fix 4740942 and provide this behaviour by default
all LaF will benefit from that 
(except Motif which is obsolete and is not supported by now)

The keyboard navigation will also be fixed
                                     
2007-07-04



Hardware and Software, Engineered to Work Together