I would like to activate my Swing application programatically. I mean that I would like to write code that cause the JFrame to be visible and focused (the window header should be highlighted). I tried to use requestFocus(). It works only if application has at least 2 windows A and B: A is hidden, B is visible. Now if I call A.requestFocus() it becomes active as I want. It does not happen if application has only one window or if both windows are invisible.
I found 2 workarounds. 1. use fake transparent undecorated frame that is always on top. This fake window will play role of window B. I did not try to implement it but it seems that it should work. 2. call A.setAlwaysOnTop(true). This brings window A on top of other windows. But it is not in focus yet. Use java.awt.Robot (mouseMove, mousePress, mouseRelease) to make a click on the header of window A. Now call A.setAlwaysOnTop(false) and return mouse pointer back to its previous position. I implemented the code and it works but it looks like an ugly workaround.
Is there a "right" solution?