Hello,
I noticed that the method "Window#toFront()" is not enough to activate a JFrame that is hidden behind other windows/applications. So I imagined the following hack, but wonder if anyone knows about a better way:
private Robot r;
...
try {
r = new Robot();
} catch (AWTException ex) {
ex.printStackTrace();
}
...
private void activateWindow(JFrame frame) {
frame.setAlwaysOnTop(true);
frame.setAlwaysOnTop(false);
Point location = MouseInfo.getPointerInfo().getLocation();
Point locationOnScreen = frame.getLocationOnScreen();
r.mouseMove(locationOnScreen.x+100, locationOnScreen.y+10);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
r.mouseMove(location.x, location.y);
}
The functionality is needed when clicking an icon in the notification area of the task bar. This should start the swing application only once. When the icon is clicked again, the started application should always activate its main window.
Regards,
André