Place JWindow always on top of JDesktopPane

asukai
asukai used Ask the Experts™
on
I have a program which displays a splash window in Jwindow, on top of a JDesktopPane. However, depending on platform, as the splash window displays before the JDesktopPane I will be hidden underneath the JDesktopPane. Can anyone tell me how to make the splash window always on the top of the JDesktopPane?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:
Try making your JDesktop's frame the owner of your JWindow.
(You specify the owner in JWindow ctor).
Mick BarryJava Developer
Top Expert 2010

Commented:
JWindow win = new JWindow(frame);

Author

Commented:
In the API the constructor of JWindows takes in type Frame. if I want to set the owner to be JFrame what should I do?
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Java Developer
Top Expert 2010
Commented:
JFrame is a subclass of Frame so you can use it.
If you are still having problems with you JDesktopPane stacking overtop of your splash screen a simple solution would be to call JWindow's toFront() method immediately after you make your JDesktopPane visible.

http://java.sun.com/j2se/1.4/docs/api/java/awt/Window.html#toFront()

However, this can create a visible 'flicker' of your splash screen.

There are other workarounds to this particular problem, however, this is one of the more simple.

{Example}
JFrame screen = new JFrame("My Program");
JDesktopPane pane = new JDesktopPane();
JWindow splash = new JWindow(screen);
/*...Code to set up splash...*/
splash.setVisible(true);
/*...Code to set up pane...*/
pane.setVisible(true);
splash.toFront();
(End Example)
Mick BarryJava Developer
Top Expert 2010

Commented:

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial