I need to get current active window.
I have used KeyboardFocusManager
, for getting active window. But i am getting active window is null.
below is the code.
please provide any way to get current active window.
KeyboardFocusManager currentManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Window activeWindow = currentManager.getActiveWindow();
This single line of code should work:
Window activeWindow = javax.swing.FocusManager.getCurrentManager().getActiveWindow();
from the JavaDoc:
Returns the active Window, if the active Window is in the same context as the calling thread. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.
to get the GlobalActiveWindow, call:
javax.swing.FocusManager.getCurrentManager().getGlobalActiveWindow();
JavaDoc:
Returns the active Window, even if the calling thread is in a different context than the active Window. Only a Frame or a Dialog can be the active Window. The native windowing system may denote the active Window or its children with special decorations, such as a highlighted title bar. The active Window is always either the focused Window, or the first Frame or Dialog that is an owner of the focused Window.
Note: When your application does not have the focus, this method returns null!
Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With