JDK-7152322 : JMenuBar should not be focusable by default
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2012-03-08
  • Updated: 2014-03-28
  • Resolved: 2014-03-28
Related Reports
Relates :  
Description
SYNOPSIS
--------
JMenuBar should not be focusable by default

OPERATING SYSTEM
----------------
All

FULL JDK VERSION
----------------
All
               
DESCRIPTION from LICENSEE
-------------------------
JMenuBar instances are focusable by default. This can prevent keyboard focus traversal when the application contains a JMenuBar.

The attached testcase demonstrates the problem. Focus moves to the JMenuBar after the JTree. and it's there is cannot be moved anywhere else, because the focus traversal keys are disabled in the JMenuBar (despite the fact that it is focusable).

As far as we can tell, JMenuBar instances are not designed to be focusable. For example, the evaluation of CR 4707457 states:

   "Menu elements do not receive focus since release 1.4.
    Thus is not a bug, because the focusLost and focusGained events
    never meant to be used to determine the status of the menus and
    menu items."

Therefore the fix would seem to be as simple as setting JMenuBar to be unfocusable by default (see suggested fix).

REPRODUCTION INSTRUCTIONS
-------------------------
1. Launch the provided testcase (instructions included in the README file)
2. Select "Container Order" traversal policy
3. Now use TAB to traverse the application components

Observed result:
Focus traversal becomes impossible after it moves away from the JTree, because it is "stuck" at the JMenuBar

Expected result:
Focus traversal should not become "stuck" at the JMenuBar
       
SUGGESTED FIX
-------------
Provided in the Suggested Fix section of the CR.

Comments
EVALUATION this bug is suspicious, I doubt we should fix it.
16-03-2012

EVALUATION It seems that problem and the suggested fix are related to Swing area.
11-03-2012

SUGGESTED FIX IBM has provided these diffs. They are relative to the latest Java 7 code. IBM is using this fix in their 1.4.2, 5.0 and Java 6 JDK implementation and has not experienced any adverse effects or complaints from customers. --- jdk/src/share/classes/javax/swing/JMenuBar.java (revision 10829) +++ jdk/src/share/classes/javax/swing/JMenuBar.java (working copy) @@ -109,6 +109,7 @@ public JMenuBar() { super(); setFocusTraversalKeysEnabled(false); + setFocusable(false); setSelectionModel(new DefaultSingleSelectionModel()); updateUI(); } *** (#1 of 1): [ UNSAVED ] ###@###.###
08-03-2012