Skip to main content

JFrame declared as setAlwaysOnTop doesn't stay on top during slide show

1 reply [Last post]
ravindra_appikatla
Offline
Joined: 2010-03-30

Hi,

We came across a very typical difference in the behavior or JFrame and JWindow.

We are maintaining a desktop application developed in java swing with one of the functionality to capture the screen. The application is a JFrame with various buttons added to it. The JFrame is set as setAlwaysOnTop(true). This screen capture works fine for all cases expect when OpenOffice presentation is running in slideshow mode on Ubuntu 8.04.

When the slideshow for presentation is activated, the presentation is coming on top of JFrame. Even though JFrame is declared as setAlwaysOnTop, it is not coming on top of slideshow. This is preventing the user from initiating the capture. This is happening only on Ubuntu (Linux Flavor). It works fine on Windows.

When we made a minor change (i.e. changed the JFrame to JWindow), it is staying always on top even when slideshow is activated.

Please go though the below example code. When the below code is run, the JFrame stays on top till a presentation is opened and slideshow activated. When slide show is running, it goes behind the slide show. If you change the JFrame to JWindow (shown in commented line), it is staying always on top even when slideshow is activated and we don’t even have the setAlwaysOnTop() property for JWindow.

<br />
import javax.swing.JFrame;<br />
import javax.swing.JWindow;</p>
<p>public class TopJFrameTester {</p>
<p>            public static void main(String[] args) {</p>
<p>                        //JWindow topContainer = new JWindow();<br />
                        JFrame topContainer = new JFrame();<br />
                        topContainer.setSize(300, 300);<br />
                        topContainer.setAlwaysOnTop(true);<br />
                        topContainer.setVisible(true);<br />
            }</p>
<p>}<br />

Can anybody explain how can I make my JFrame to sit on top of PPT slide show as that of JWindow or any workaround to achieve this?

Any help in this regard is highly appreciated.

Thanks & Regards,
Ravindra Appikatla

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24

Hi Ravindra,

The specification of the setAlwaysOnTop() methods clearly states:

"If some other window already is always-on-top then the relative order between these windows is unspecified (depends on platform). No window can be brought to be over always-on-top window except maybe another always-on-top window."

See: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Window.html#setAlwaysOnTop(boolean)

As to the effect with the JWindow, that works till java 1.6 only. Since Java 1.7 even plain JWindows won't work that way, because they are no longer made override-redirect windows which made them being truly on top of everything else (see [1] for details).

[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6380835

--
best regards,
Anthony