Example usage for java.awt KeyboardFocusManager getActiveWindow

List of usage examples for java.awt KeyboardFocusManager getActiveWindow

Introduction

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

Prototype

public Window getActiveWindow() 

Source Link

Document

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

Usage

From source file:Main.java

public static Window getActiveWindow() {
    KeyboardFocusManager mgr = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    return mgr.getActiveWindow();
}

From source file:Main.java

/**
 * Tries to find the current focused window.
 * //from   w  w w . ja  va  2s  . co m
 * @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;
}