JDK-4212563 : JPopupMenu doesn't support arrow key navigation or Enter
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.1,1.1.6,1.2.2
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt
  • CPU: generic,x86
  • Submitted: 1999-02-18
  • Updated: 2000-11-17
  • Resolved: 2000-11-17
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.
1.4.0 betaFixed
Related Reports
Relates :  

Name: clC74495			Date: 02/18/99

Code to repro at end.  Click on "Press me", then try to
use the arrow keys or enter to dismiss the popup menu.
(I'm using Swing 1.1.1-beta1)

This is a pretty nasty limitation that can have implications
for handicapped users - even if we make showing the JPopupMenu
keyboard accessible (e.g., via Shift-F10), the menu itself
isn't accessible at all).

(Various bugs have been filed against related issues -
Esc key not working, accelerators not working - but none
against this per se as far as I can see)

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

public class PopupMenu extends JPanel
  static public void main(String[] args)
    JFrame frame = new JFrame();
    frame.setContentPane(new PopupMenu());
    frame.setSize(400, 400);

  public PopupMenu()
    final JButton test = new JButton("Press me!");
    test.addActionListener(new ActionListener()
      public void actionPerformed(ActionEvent e)
        JPopupMenu popup = new JPopupMenu();
        popup.add("Item 1");
        popup.add("Item 2");
        popup.add("Item 3");
        popup.show(test, 0, 0);

(Review ID: 54311)

Name: skT88420			Date: 04/21/99

My JApplet has a JMenuBar.  When the JPopupMenu shows out side of the JApplet boundary, the left and right arrow keys do not work properly.  It seems that once the JPopupMenu shows outside of JApplet, it is stuck there.

<APPLET CODE=MixPopupTest.class Width=400 HEIGHT=480></APPLET>

Here is the source code:

import java.awt.*;
import java.applet.*;
import javax.swing.*;

public class MixPopupTest extends JApplet {

   public void init() {

	JMenuBar menubar = new JMenuBar();

	// Create lightweight-enabled menu
        JMenu menu = new JMenu("Lite Menu");
        menu.add("Fruit Plate");
	// Create lightweight-disabled menu
	for (int i = 0; i < 5; i++ ) {


	   menu = new JMenu("Heavy Menu " + i);
	   menu.add("Filet Mignon");
	   menu.add("Banana Split");
	   menu.add("A very very very long item");
	getContentPane().add("Center", box);


java -fullversion: java full version "JDK1.1.5K"

swing version: 1.1 RELEASE

Name: vi73552			Date: 06/22/99

Popup menus do not accept keyboard input at all - according to 
the Swing API, up/down arrows should move the highlighted item,
space bar should select, and so on.

To reproduce the problem compile the following source code, run
the application, and click the mouse to bring up the popup.
Shift + F10 is supposed to bring up the menu as well, but this
doesn't work, although according to the Swing API it should.

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

public class PopupBug extends JFrame{
  private JPopupMenu popup;
  public PopupBug(){
  private void init(){
    addMouseListener(new MouseAdapter(){
      public void mousePressed( MouseEvent e ){
      public void mouseClicked( MouseEvent e ){
      public void mouseReleased( MouseEvent e ){
  private void setPopup(){
    popup = new JPopupMenu();
    JMenuItem item;
    popup.add(item=new JMenuItem("Confirm"));
    popup.add(item=new JMenuItem("Add"));
    popup.add(item=new JMenuItem("Delete"));
    popup.add(item=new JMenuItem("Print"));
    popup.add(item=new JMenuItem("Quit"));
  private JFrame getThis(){return this;}
  public static void main(String[] args){
    new PopupBug();

No errors occurred, it just doesn't work.

Output of -version = 1.1.7A
<I have reproduced it under JDK1.2.2 too, Vasya>
Output of -fullversion = JDK1.1.7A IBM build o117-19981120 
  (JIT enabled:javax)

This was in OS/2 - the problem also occurred in NT
(Review ID: 84639)

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta

WORK AROUND Name: clC74495 Date: 02/18/99 Add code akin to BasicComboPopup.InvocationKeyHandler to explicitly track the necessary keys on the focused component and manually move the selection around. Blech. ======================================================================


EVALUATION This is not a regression (it has never worked). --- This is very nasty bug and the solution may have a lot of serious implications. Part of the problem is that the JPopupMen doesn't grab the focus when it is shown. That way, the focus is not removed from the existing component. If we were to give the JPopupMenu focus when it is shown, then it could wreak havoc in components which will now get the "focusLost" message (like JTable cells). This would be new behaviour which could break a lot of existing applications. Another possible solution is to add new a new show() method which has a flag that would indicate that the popup should grab the focus. In any case, we all understand that it's a very serious problem and will commit to fix this for the next major release. mark.davidson@Eng 2000-10-25 This will be fixed for the 1.4 beta. I'm very close to finishing the implementation and it's been very tricky. My testing is pretty thorough but I may be breaking some applications out there since I am rearchictecting some of the existing semantics of JPopupMenu and JMenu and moving around a lot of code. The approach that I've taken has been: - Migrate the sharedActionMap, private inner classes and selected window input map bindings from BasicMenuUI into BasicPopupMenuUI - Moved the logic of managing focus and registering the InputMaps from BasicMenuUI.ChangeHandler to BasicPopupMenuUI.PropertyChangeHandler. - JPopupMenu will now process KeyEvents and forward them to the default MenuSelectionManager. The largest implication of these changes is that the JPopupMenu will gain the focus when it is visible. Previously, the popup menu would never get the focus. If the popup menu was used in the context of a JMenu then the JMenu would have the focus and manage the MenuElement and selection which would affect the selected menu item in the popup menu. Now the popup menu manages the selected menu element which removed it dependency on JMenu (which was the root of the original problem). Direct any comments to me (internal customers) or ###@###.### (external customers). mark.davidson@Eng 2000-11-14 Fixed in merlin beta. Solaris implementation doesn't work because of focus manager regression. Solaris will be fixed by beta. mark.davidson@Eng 2000-11-16