jdk/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java
changeset 39016 f52c1429ae85
parent 37694 c064aefc5a2f
child 42191 e5ba7d74e3c6
--- a/jdk/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java	Tue May 31 16:03:21 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java	Tue May 31 15:57:01 2016 +0300
@@ -148,9 +148,20 @@
         Component toFocus =
             KeyboardFocusManager.getMostRecentFocusOwner(aWindow);
 
-        if (toFocus != null && toFocus != vetoedComponent && doRestoreFocus(toFocus, vetoedComponent, false)) {
-            return true;
-        } else if (clearOnFailure) {
+        if (toFocus != null && toFocus != vetoedComponent) {
+            Component heavyweight = getHeavyweight(aWindow);
+            if (heavyweight != null) {
+                setNativeFocusOwner(heavyweight);
+                Toolkit.getEventQueue().createSecondaryLoop(
+                        () -> getGlobalFocusedWindow() != aWindow, null, 50)
+                        .enter();
+            }
+            if (getGlobalFocusedWindow() == aWindow &&
+                              doRestoreFocus(toFocus, vetoedComponent, false)) {
+                return true;
+            }
+        }
+        if (clearOnFailure) {
             clearGlobalFocusOwnerPriv();
             return true;
         } else {