Shortcuts in Swing? (question for pals from Apple)

Mike Swingler swingler at apple.com
Sun Dec 4 09:58:11 PST 2011


On Nov 22, 2011, at 9:22 AM, Scott Kovatch wrote:

> On Nov 21, 2011, at 11:11 AM, Alexander Potochkin wrote:
> 
>> We have a code snippet which tests the various shortcuts in a simple Swing application,
>> Alt+A and Alt+B are among them.
>> 
>> It turned out that when the focus is inside a JTextArea,
>> Alt+A works as expected but Alt+B types a special symbol.
>> 
>> This behavior is different from what we have on Windows or Linux
>> and our testers consider it as a bug.
> 
> That test is making an invalid assumption that Alt is the shortcut accelerator on all platforms, and it isn't. In fact, I consider it a bug that Alt-A does not produce 'å' in that case.
> 
> On the Mac, Alt maps to the option key, which is what you use in combination with other keys to type many non-ASCII Roman symbols. The equivalent behavior of Alt on Windows or Linux is the Command key. This has always been the case on the Mac.
> 
> Somewhere in the Aqua L&F there is a mapping of key combinations to actions. It sounds like Alt+A may be mapped to 'select all'.
> 
>> Is there any workarounds to suppress typing on Alt+B?
>> (Alt+B + some other magic keys?)
> 
> You really don't want to change the behavior of Alt-B without a good reason, as users expect to see a character when you type Alt-B ('∫'). It's hard to answer this without seeing what the test is actually looking for. 
> 
>> By the way, how to move the focus out of a focused JTextArea on Mac?
>> On windows we use Ctrl+Tab, but it doesn't work on Mac.
> 
> It should be Shift+Tab. If it doesn't work that's a bug.

I wanted to circle back on this thread:

While "accelerators" are not a Mac OS X concept, we understand that some Java applications expect this functionality to be available (especially if they do not opt-into using the screen menu bar). Our best recommendation so far is to use Ctrl-Alt as the accelerator key mask, because it will not interfere with the Option-key extended character input method (and Ctrl is rarely used for direct command invocation on the Mac, in lieu of Command (a.k.a. Meta)).

Cheers,
Mike Swingler
Apple Inc.



More information about the macosx-port-dev mailing list