<Swing Dev> [Accessibility]Focus unable to traverse in the menubar

Neil Richards neil.richards at ngmr.net
Mon Oct 10 15:01:14 UTC 2011


On Mon, 2011-10-10 at 16:56 +0400, Anton Tarasov wrote:
> Hi Neil and Jing, 

> I'm afraid that it's wrong to use ContainerOrderFocusTraversalPolicy
> for swing components. This policy is designed for AWT.
> JMenuBar calls setFocusTraversalKeysEnabled(false) in its ctor which
> means that it "swallows" focus traversal keys (like TAB/SHIFT-TAB
> etc.)
> and so it can't be a member of a focus traversal chain. Swing's
> default traversal policy (LayoutFocusTraversalPolicy) excludes
> JMenuBar
> from a focus traversal cycle. ContainerOrderFocusTraversalPolicy is
> not "aware" about JMenuBar and so it allows it.
> 
> So, either a default Swing policy should be used, or a custom policy.
> At worst, ContainerOrderFocusTraversalPolicy should be overriden
> to exclude JMenuBar from a cycle (override its accept(Component)
> method). 
> 
> Thanks,
> Anton.

Hi Anton,
Thanks for reviewing the suggestion, and for your insights into this
scenario.

>From the Javadoc, it seems that setFocusTraversalKeysEnabled() is mainly
concerned with choosing whether focus traversal key presses (normally
TAB and SHIFT-TAB) are processed "automatically" (when 'true') or are
delivered to the Component as key events (for the component's code to
process "manually").

(In the case of JMenuBar, it makes them come through as key events, but
doesn't do anything special to process these events, which is why they
get discarded.)

Your description above, though, seems to suggest that it is generally
undesirable for the JMenuBar to be given the focus, as all the
Swing-aware focus traversal policies make a point of not giving focus to
JMenuBar items.

If this is so, then wouldn't it make sense to call setFocusable(false)
from its constructor (too), to ensure it doesn't get focus ?

Or, to put it another way, could you explain a little of the reasoning
or scenario behind why it is desirable for JMenuBar items to be
generally focusable, even though they aren't focus-traversable ?

I think such an explanation would be really helpful in clearing up my
confusion on this point.

Thanks, Neil

-- 
Unless stated above:
IBM email: neil_richards at uk.ibm.com
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU




More information about the swing-dev mailing list