Example usage for java.awt KeyboardFocusManager getFocusedWindow

List of usage examples for java.awt KeyboardFocusManager getFocusedWindow

Introduction

In this page you can find the example usage for java.awt KeyboardFocusManager getFocusedWindow.

Prototype

public Window getFocusedWindow() 

Source Link

Document

Returns the focused Window, if the focused Window is in the same context as the calling thread.

Usage

From source file:Main.java

/**
 * Tries to find the current focused window.
 * /*w w w . j av  a 2s. c  om*/
 * @return the current focused window, or <code>null</code> if no such window
 *         could be found.
 */
public static final Window getCurrentWindow() {
    Window owner;
    final KeyboardFocusManager kbdFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    owner = kbdFocusManager.getFocusedWindow();
    if (owner == null) {
        owner = kbdFocusManager.getActiveWindow();
    }
    return owner;
}