5

We are developing a rather big Java enterprise application with a traditional Swing client.

Every now and then, we facing the problem that random JDialogs and JFrames open up and getting the focus, but are hidden behind their parent windows.

Unfortunately, this phenomenon is not reproducible and happens on occasion. So far it was recognized on machines having Win7 and WinXP installed. Since all developers running Windows operating systems, that does not necessarily mean that this problem is specific to Windows.

I have no idea how to fix the problem. Maybe there is a Swing expert out there who can fix this? (We are still on with Java 6).

user unknown
  • 35,537
  • 11
  • 75
  • 121
Stefan Kolb
  • 81
  • 1
  • 4

3 Answers3

4

JFrames should not have "parents" as they are meant to be the "parent-most" window of an application. If you have a window that is meant to be a "child" and is therefore meant to be above another window, then it should be a dialog such as a JDialog or JOptionPane and should have its parent window set accordingly.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Thank's for the info, but it does not selve the problem. As already stated: The behaviour also occures when using JDialogs. It is irritating that it happens just every now and then and not on a regular basis. – Stefan Kolb Mar 23 '12 at 12:09
  • @Stefan: But you don't mention whether you have checked to be sure that all dialogs have their parents set appropriately. Without this information and perhaps without an [sscce](http://sscce.org) which would allow us to reproduce your problem, I fail to see how we can help you. – Hovercraft Full Of Eels Mar 23 '12 at 15:20
  • As I said, it is NOT reproducible and happens – Stefan Kolb Mar 26 '12 at 09:17
2

I once had the same problem: The error was that the JDialog's/JFrame's parent was in fact not set properly. I set it to the parent of the parent, which caused the issue.

mort
  • 12,988
  • 14
  • 52
  • 97
  • Thanks, I am about to check the line where the parent is set. But the funny thing is that it happens not on a regular basis. Was it the same in your case? – Stefan Kolb Mar 23 '12 at 12:06
  • I don't really remember. For me, the funny thing was that it happened only the first time the child was opened - I then clicked on my UI, which brought the child to the front. Closing the child and reopening again would result in the child being in the front. – mort Mar 23 '12 at 12:50
1

Try to add a FocusListener and listen for focus gained event where you can call yourWindow.toFront(). setAllwaysOnTop() could be interesting for you too.

lzdt
  • 489
  • 1
  • 6
  • 17