JDK-4622001 : REGRESSION: Keyboard navigation in JMenuBar is incorrect.
  • 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-01-10
  • Updated: 2002-05-17
  • Resolved: 2002-05-17
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 01/10/2002


java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)

DESCRIPTION OF THE PROBLEM :

Wrong keyboard navigation into JMenuBar. In Swing application (see applied source), I have JMenuBar.
Use F10 key to go in the first JMenu ("File"). Here all is OK. Try to go to JMenuItem ("Open") below. But 
when you press Down_Arrow key, the system menu is selected. This is a bug (which not exist in the JDK 1.3.1).
Interesting side effect is when you see mentioned above system menu, if you press ESC and again ESC, 
keyboard navigation in the JMenuBar is OK.

Now start the program again. Press F10 and try to select next JMenu ("Edit"). But when you press the Right_Arrow key
nothing happen. This is a bug too (with JDK 1.3.1 the same code works OK).

The problem is reproducible on Windows 2000, Windows Nt 4.0, Win 98 using JDK1.4.0-beta3.


REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Press F10
2. Press down arrow key


EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected : focus to first JMenuItem.
Result : system menu is selected.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;



/**
 * This program demonstrate bug when using keyboard to navigate in menu
 * bar (with JDK 1.4 beta 3). Start the program, then press F10 and try to
 * select different menus. Next compile and run the same program under
 * JDK 1.3.1. Then you'll see the difference.
 *
 */
public class MenuBug
{
    /**
     * Creates new MenuBug object.
     *
     */
    public MenuBug()
    {
       // Create test frame
       javax.swing.JFrame f = new javax.swing.JFrame("Test menu bug");
       f.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
       f.setSize(400, 300);
       java.awt.Dimension dim = java.awt.Toolkit.getDefaultToolkit().
           getScreenSize();
       f.setLocation(dim.width/2 - f.getWidth()/2, dim.height/2 -
           f.getHeight());
    
       // Create menus
       JMenuBar mb = new JMenuBar();
       f.setJMenuBar(mb);

       JMenu mF = new JMenu("File");
       mb.add(mF);

       JMenuItem miO = new JMenuItem("Open");
       mF.add(miO);

       JMenuItem miE = new JMenuItem("Exit");
       mF.add(miE);

       JMenu mE = new JMenu("Edit");
       mb.add(mE);

       // Make all visible
       f.setVisible(true);
    } // constructor()



    /**
     * Entry point.
     *
     * @param args Command line arguments.
     */
    public static void main(String[] args)
    {
        try
        {
            MenuBug app = new MenuBug();
        }
        catch(Throwable exc)
        {
            exc.printStackTrace();
            System.exit(-1);
        }
    } // main
} // MenuBug


---------- END SOURCE ----------
(Review ID: 137994) 
======================================================================

Comments
EVALUATION Name: pzR10082 Date: 01/14/2002 F10 is used by Windows to activate system menu. We can theoretically forbid processing of a key event by Windows. This is done by consuming the key event. However, in Swing, F10 key (like any other InputMap keybinding) is processed by a KeyEventPostProcessor, i.e. after the event has been seen by Windows. So Swing sees the event after Windows has processed it. ###@###.### 2002-01-14 ====================================================================== Name: pzR10082 Date: 01/15/2002 This is a regression from #4390019. In java.awt.Component.dispatchEventImpl(), a block of code was added to facilitate native event processing in case when focus owner is lightweight. The problem is that this block is executed before any KeyEventPostProcessor handles the event. In Swing, WHEN_IN_FOCUSED_WINDOW keybindings are implemented using a KeyEventPostProcessor, so we cannot prevent the F10 key event from being handled by Windows. It seems that the code block in dispatchEventImpl() can be relocated safely so that it gets executed after KeyEventPostProcessors have returned. ###@###.### 2002-01-15 ======================================================================
15-01-2002