Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I move another program's window to the front of focus?

Tags:

java

windows

I am interacting with a third party application using it's API, and would like to move it to the front of focus (so that it is on top of all other open windows) when a user performs a certain action. While I can move my application up and down in the hierarchy pretty easily, there doesn't appear to be a way to interact with other windows. Is it possible to move another program's window to front with Java?

like image 364
TwentyMiles Avatar asked Apr 22 '10 20:04

TwentyMiles


People also ask

How do I force an application to the front?

To make the active window always on top, press Ctrl + Spacebar (or the keyboard shortcut you assigned). Press the keyboard shortcut again to disable “always on top” for the active window. For script options, right-click on the AutoHotkey icon in the system tray.


1 Answers

You can't do it in pure Java code, but you could using JNI. See In Java Swing how do you get a Win32 window handle (hwnd) reference to a window? for how to get a handle to the window. Then you could do something like http://msdn.microsoft.com/en-us/library/ms633545 to move it to the front.

Caveat: This is for windows only

like image 172
Jeff Storey Avatar answered Oct 05 '22 01:10

Jeff Storey