--- old/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java 2016-02-25 16:23:52.201848999 +0530 +++ new/src/java.desktop/share/classes/java/awt/DefaultKeyboardFocusManager.java 2016-02-25 16:23:52.049773000 +0530 @@ -355,6 +355,12 @@ setGlobalFocusedWindow(null); } } + + Component comp = KeyboardFocusManager. + getMostRecentFocusOwner(newFocusedWindow); + if (comp != null) { + setGlobalFocusOwner(comp); + } // Because the native libraries do not post WINDOW_ACTIVATED // events, we need to synthesize one if the active Window --- /dev/null 2016-02-25 15:40:14.562905000 +0530 +++ new/test/java/awt/Frame/MostRecentFocusOwner/MostRecentFocusOwnerTest.java 2016-02-25 16:23:52.518007000 +0530 @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + /* + @test + @bug 6211389 + @summary Verify MostRecentFocusOwner when Window Gained Focus. + @run main MostRecentFocusOwnerTest + */ +import java.awt.Component; +import java.awt.Frame; +import java.awt.Robot; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +public class MostRecentFocusOwnerTest { + + private static Component focusComponent = null; + private static Frame frame; + private static TextArea textArea; + private static TextField textField; + + private static void CreateAndShowUI() { + + frame = new Frame("Test"); + frame.setLayout(new java.awt.FlowLayout()); + textArea = new TextArea("TextArea", 5, 10); + textField = new TextField("TextField", 10); + + frame.add(textArea); + frame.add(textField); + frame.pack(); + + frame.addWindowFocusListener(new WindowAdapter() { + public void windowGainedFocus(WindowEvent e) { + focusComponent = frame.getMostRecentFocusOwner(); + } + + }); + frame.setVisible(true); + + } + + public static void main(String[] args) throws Exception { + + CreateAndShowUI(); + + Robot robot = new Robot(); + frame.setExtendedState(Frame.ICONIFIED); + robot.waitForIdle(); + frame.setExtendedState(Frame.NORMAL); + robot.waitForIdle(); + if (focusComponent != textArea) { + throw new RuntimeException("MostRecentFocusOwner is Null" + + " When window GainedFocus"); + } + + robot.waitForIdle(); + textField.requestFocus(); + frame.setExtendedState(Frame.ICONIFIED); + robot.waitForIdle(); + frame.setExtendedState(Frame.NORMAL); + robot.waitForIdle(); + if (focusComponent != textField) { + throw new RuntimeException("MostRecentFocusOwner is Null" + + " When window GainedFocus"); + } + + frame.dispose(); + + } + +}