United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7144063 [macosx] Swing JMenu mnemonic doesn't work; hint misleading; cross symbol typed
JDK-7144063 : [macosx] Swing JMenu mnemonic doesn't work; hint misleading; cross symbol typed

Details
Type:
Bug
Submit Date:
2012-02-09
Status:
Closed
Updated Date:
2012-06-06
Project Name:
JDK
Resolved Date:
2012-04-05
Component:
client-libs
OS:
os_x
Sub-Component:
javax.swing
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u4 (b18)

Related Reports
Backport:

Sub Tasks

Description
Mac OS X 10.7.3 macmini4,1 standard Mac keyboard
Run 
closed/java/awt/swing/event/KeyEvent/MenuShortCut/JActionCommandTest.
You will see a JMenu with item providing a hint "Alt T" (alt displayed as a zigzag). You may click and get a proper action from there.

Now focus in a textfield and press Alt+t or Ctrl+Alt+t as it used to be some builds ago: there will be no action. Moreover, on Alt+t you'll see a dreadful symbol "dead" (a cross) typed in the text field! Long live Swing.

                                    

Comments
PUBLIC COMMENTS

Build: b227
closed/java/awt/swing/event/KeyEvent/MenuShortCut/JActionCommandTest
                                     
2012-02-09
EVALUATION

The behavior of Apple JDK is the following. When I type Alt+F, the special unicode symbol appears in the textfield and the menu gets activated simultaneously. When I type Alt+T, the special unicode symbol appears
in the textfield but the menu doesn't get activated. (Other Alt+key conminations behave the first of the
second way).

I digged the open jdk and found the following. [AWTView insertText] is called on typing Alt+key.
This is a method of NSTextInputClient protocol. Then some conditions are checked and the java
CInputMethod.insertText(String) method is called. Among those conditions there's a utf8 str length check.
If it's greater than 2, the java method is called. It creates an appropriate InputMethodEvent which is then posted, dispatched and the unicode symbol appears in the text field.

Otherwise, the key event is delivered to CPlatformResponder where it creates a KEY_TYPED event and packes
the two bytes unicode character into it. It is then treated as mnemonic and the menu is activated.

Alt+F generates a utf8 symbol of two bytes size, Alt+T generates a symbol of 3 bytes. That's the difference.

Simply ignoring the condition (utf8length > 2) in [AWTView insertText] makes all the Alt+key symbols appear
in the text field. The menu is no longer activated. For me, this behavior looks right for Mac. (The menu
gets activated by Alt+key being typed only on non-text components). I'm not sure what is the right fix though
(the change I suggested is just a try).
                                     
2012-02-10
EVALUATION

Attached a simple test case which shows the above scenario.
                                     
2012-02-10
EVALUATION

I titally agree that we have to raise inputMethod event for any complex character that came to the insertText routine and lowering limit of the utf8charwisth to >1 byte should solve that problem.
                                     
2012-02-14



Hardware and Software, Engineered to Work Together