I have a javafx application for Windows which launches a selenium chrome window Here is the process flow:
At this point in time the chrome window has system focus. I would like the java application to have focus instead. Yes the user can use Alt + tab but I would want the user to be able to interact with my java application immediately. Things I have tried:
setForegroundWindow on my application windowHowever this only causes the icon on the taskbar to flash but the focus is still with the selenium window. Here is the code snippet.
if (PlatformSpecific.isOnWindows()) {
// Restores browser window if it is minimized / maximized
user32.ShowWindow(browserWindowHandle, WinUser.SW_SHOWNOACTIVATE);
// SWP_NOMOVE and SWP_NOSIZE prevents the 0,0,0,0 parameters from taking effect.
logger.info("Bringing bView to front");
boolean success = user32.SetWindowPos(browserWindowHandle, mainWindowHandle, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
if (!success) {
logger.info("Failed to bring bView to front.");
logger.info(Kernel32.INSTANCE.GetLastError());
}
user32.SetForegroundWindow(mainWindowHandle);
}This code is called right after the chrome window is launched. But it always fails to bring my main application to foreground with error code 1400. I think it has something to do with the java thread unable to execute this being in the background. Any help would be much appreciated !