I have a Java swing program consisting of many JFrames, I know not the best design, but it does the job.
If I open another program, for example Firefox, and maximize that window, my JFrames are not visible.
Now when I click the button on the window taskbar of one of my JFrames the JFrame popups up.
When this JFrame popups up I need check if one of my other JFrames are visible, I mean are in front of Firefox window.
I tried isVisible()
, isShowing()
and isDisplayable()
, but they always return true even when the JFrame is below the Firefox window. That makes sense when reading the Java documentation.
But I can't seem to find a method to tells me if my JFrame is really visible in front of the Firefox window.
It puzzles me.
A JFrame covered by Firefox has the following properties:
14:50:08,129 DEBUG DrawFrame - isVisible: true
14:50:08,129 DEBUG DrawFrame - isDisplayable: true
14:50:08,129 DEBUG DrawFrame - isShowing: true
Just to explain my goal: I have multiple JFrames and when I click one specific JFrame button on the window taskbar I want to check if another JFrame is visible for the user. If it is not visible for the user (for example when covered by another program) than I want to make it visible. Making it visible is simple: WindowListener windowActivated and call toFront on the not visible frame, but of course this causes a loop when the other JFrame is activated again (calling windowActivated > toFront > windowActivated > toFront, and so on). That is why I need to check the visibility before calling the toFront method.
I'm not aware of a function in Java to check if a window is visible for the user, so going native may be the only solution.