JDK-7157015 : [macosx] Situation when KeyEventDispatcher doesn't work on AWT but does on Swing.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-03-27
  • Updated: 2014-09-23
  • Resolved: 2012-09-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u40Fixed 8 b56Fixed
Description
Mac OS X 10.7.3 macmini4,1
Run the attached application creating JFrame, JButton and JList. It has a custom keyboard focus manager and a key dispatcher. Once the frame is shown, we request focus for the button (it will paint its outline as if focused) and press a key. Key event dispatcher reports everything properly.

So far so good. Now run the same application with Frame, Button and List. Button still paints outline as if focused but no key events come to the KED. Even if we click the Button, it doesn't help. Events start going only after we click the List and Button again.

Comments
noreg-low because it doesn't affect swing.
26-08-2013

EVALUATION See Evaluation & Comments for 6981400/8.
31-08-2012

EVALUATION Since the fix for 6981400 contains a fix for this CR, no separate fix is required. Anton is going to push the fix for 6981400 into 7u8, thus fixing this CR as well.
27-08-2012

EVALUATION While working on 6981400 for jdk7u I've faced with the same issue. The method LWWindowPeer.dispatchKeyEvent was found wrong. The point is that it should do its best to post the key event upward as soon as it came to the native toplevel. So, if the focus owner returned by LWKFMPeer is null the target of the key event should be set to LWWindowPeer itself. DKFM will further dispatch the event to the current java focus owner. The same way it works on other toolkits. Why LWKFMPeer returns null is a separate question, though. The fix for 6981400 contains changes which address this issue. Here's it (the second chunk): http://cr.openjdk.java.net/~ant/6981400/webrev.3/src/macosx/classes/sun/lwawt/LWWindowPeer.java.udiff.html I checked that this fixes the test case.
18-04-2012

EVALUATION I can reproduce it with latest jdk7u4 (b18) and rarely with jdk8. Here's what I've got so far debugging it. When the frame opens the focus log shows a picture that looks correct. The button does get focus, no failures are logged. Then I press a key and the LWWindowPeer.dispatchKeyEvent method (where I put printing) reports the focus owner is null. At the same time, KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() returns the button. Thus, something is wrong with how we manage app contexts: LWComponentPeer focusOwner = LWKeyboardFocusManagerPeer.getInstance(getAppContext()). getFocusOwner();
28-03-2012