<Swing Dev> [Accessibility]Focus unable to traverse in the menubar
Anton Tarasov
anton.tarasov at oracle.com
Mon Oct 10 12:56:05 UTC 2011
Hi Neil and Jing,
On 10/5/2011 7:38 PM, Pavel Porvatov wrote:
> Hi Neil and Jing,
>> On Mon, 2011-09-19 at 13:52 +0400, Pavel Porvatov wrote:
>>> Hi Jing,
>>>
>>> I can't agree with you about the problem. According to
>>> http://download.oracle.com/javase/tutorial/uiswing/components/menu.html
>>> "Menus are unique in that, by convention, they aren't placed with the
>>> other components in the UI". Instead, a menu usually appears either
>>> in a
>>> menu bar or as a popup menu", so your test-case is invalid.
>> Hi Pavel,
>> I'm not sure I understand your objection to the testcase.
>>
>> As you can see from the testcase code, the JMenu component _is_ held by
>> a JMenuBar component, in concordance with the documentation you point
>> to.
> Yep, that was my mistake. BTW the test treats with JMenu in a strange
> way. Actually the test should contain something like this:
> JMenuBar menubar = new JMenuBar();
> JMenu jMenu = new JMenu("sample menu");
> jMenu.add(new JMenuItem("hello"));
> menubar.add(jMenu);
>
>> Perhaps you're worried that the physical layout of the components in the
>> panel materially affects the nature of the problem being reported ?
>>
>> If so, please consider the modified testcase in an update to the webrev
>> I previously posted [2].
>>
>> The modification uses the BorderLayout manager instead of GridLayout,
>> adding the JMenuBar so that it appears at the top of the panel.
>>
>> You'll notice that this rearrangement in physical layout does not change
>> the nature of the problem being reported.
>>
>> Hope this helps to clarify things,
>> Regards, Neil
> The fix changes default value of the JMenuBar.Focusable field and so
> it breaks backward compatibility.
>
> Moreover the test have many other problems, but not only in JMenuBar:
> 1. Shift-TAB doesn't work from JComboBox
> 2. TAB from the last Button moves focus to some non-interactive
> component and next TAB pressing doesn't change focus state at all
>
> May be the ContainerOrderFocusTraversalPolicy should be fixed...?
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.
>
> P.S. CC-ed Anton as a focus expert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20111010/e18a5b67/attachment.html>
More information about the swing-dev
mailing list