Shortcuts in Swing? (question for pals from Apple)

Scott Kovatch scott.kovatch at oracle.com
Tue Nov 22 09:22:55 PST 2011


	
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.

-- Scott



More information about the macosx-port-dev mailing list