GUI in 2Dimensions

Flexing with Swing

Archive for October, 2009

Java Swing Application ‘Always on Top’

Posted by Pavan Kumar on October 14, 2009

Since the last few weeks  , our  Java Swing Client  sporadically..seems to set itself  on top of every other windows application.  As things always happen, the problem was occasionally reproducible by our testing team, but  not  by our development team..but it was a big problem for our clients to have their numerous window apps  open behind our Swing app.

So finally I decided to investigate further ….a cursory search in the Sun Bug Database took me to

which explains the issue wonderfully….and the best  part was that  it was always Reproducible !

The bug states that  ‘Modal dialog causes the underlying parent JFrame to be set to Always on top’. Here are the steps to reproduce the bug

1) Open a JFrame (note the "alwaysOnTop" is not set to true).
2) Spawn a Modal Dialog with 'Always on Top' , From the Frame
3) While the dialog is open ,click on the underlying Frame (nothing happens as modal dialog is blocking it).
4) Now close the dialog and suddenly the parent JFrame is now set to be always on top. It won't happen if  the parent Frame ,was NOT clicked on while the dialog was open.

The worst part of the bug is the fact that ‘Always On Top’ property of the Frame is false although the Frame itself is visually always on top.

One workaround as mentioned is to ..

setAlwaysonTop(true)..followed by….setAlwaysonTop(false) , on the Main Window whenever a modal dialog closed .

This bug seems to have crept in only after JRE 6 Update 11  , and was submitted in early April… Hopefully it would get fixed in the upcoming releases …..


Posted in GUI, Java, Swing | Leave a Comment »