1

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 javadoc.

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.

[edit] 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

[edit2]

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.

[edit3]

There doesn't seem to be a function in java to check if a window is visible for the user, so going native is the only solution, a topic on stackoverflow gave me the answer: Windows: how to get a list of all visible windows?

Cheers!

Community
  • 1
  • 1
TinusSky
  • 1,607
  • 5
  • 22
  • 31
  • Works for me on Mac OS X using this [example](http://stackoverflow.com/a/3245805/230513). – trashgod May 13 '14 at 11:45
  • The example you are referring to doesn't illustrate any checks on how to see if a frame is visible in front of another program. See my question for more information – TinusSky May 13 '14 at 12:53
  • Please define _really_ in this context. In the dock (similar to task bar), I see a checkmark next to the frontmost frame. – trashgod May 13 '14 at 12:58

1 Answers1

0
  • use windowGainedFocus/LostFocus from WindowFocusListener

  • loop in array of Window[] wins = Window.getWindows();, returns all Top-Level Containers in current JVM

  • be sure that in loop by test if (wins[i] instanceof JFrame) { (or JDialog/JWindow ...)

mKorbel
  • 109,107
  • 18
  • 130
  • 305
  • I'm not fully understand what you mean, but tracking if a frame is visible using a windowfocuslistener is not correct, cause a frame can be visible (in front of another window) when i hasn't the focus, cause another frame can have the focus. – TinusSky May 13 '14 at 12:52
  • @Tinus: Don't forget that your trying to work around [known problems with multiple frames](http://stackoverflow.com/q/9554636/230513). It may help if you explain the goal. – trashgod May 13 '14 at 13:00
  • @trashgod i've edited my question, thanks! Note: i know the limitations, the only problem this little "feature" is not worth rewriting the program's gui. I'm happy with every dirty trick even going native. – TinusSky May 13 '14 at 13:21
  • @Tinus no idea without an SSCCE/MCVE, short, runnable, compilable, seems like as your issue, topic isn't about specific methods, but in code, you can to test with [another Listeners added to JFrames](http://stackoverflow.com/questions/10880326/jpanel-which-one-of-listeners-is-proper-for-visibility-is-changed), isXxx couldn't be proper notifiers, nor clear from which of the nested JFrames classes is event fired, forgot for isDisplayable, is notifier about health of this container – mKorbel May 13 '14 at 13:38
  • Cheers @mKorbel , a code sample is indeed always handy, but it seemed it wouldn't helped in this case, but no harm done, i've edited my question with the answer. – TinusSky May 13 '14 at 14:47