G
Glenn McCall
I am trying to create a splash screen. I would like it to be visible for a
few seconds while the application is initialising. After a timer expires,
the splash screen will close automatically. I have all of this working just
fine.
However, at some point during the application initialisation, it creates the
main window. When this occurs, the main window appears on top of the splash
screen. I would prefer that the splash screen be "top most" when this
occurs.
I have tried various combinations of toFront() and toBack() with no success
whatsoever.
How can I keep my splash screen topmost - preferably without having to mess
with "lost focus" type of events? In VC++, I could do this by creating the
splash screen window with the "TOPMOST" attribute set - but I can't find a
similar attribute in the java window classes.
TIA - Glenn Mc
P.S. For what it is worth, I have attached some snippets of the code I am
using. SplashPanel extends JPanel and contains all of the components making
up the splash screen.
public class SqlManEditor extends JFrame {
private static JWindow splash;
private static void showSplash (final int duration) {
/* final JWindow */ splash = new JWindow ();
SplashPanel content = new SplashPanel ();
splash.setContentPane(content);
splash.pack ();
// Center the splash screen in the display.
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize ();
int x = (screen.width - content.getWidth()) / 2;
int y = (screen.height - content.getHeight()) / 2;
splash.setBounds (x, y, content.getWidth(), content.getHeight());
Thread r = new Thread () {
public void run () {
// TODO: Figure out how to get the splash screen
to be "topmost"
// Currently when the main window is
created, it will appear
// in front of the splash screen.
splash.setVisible (true);
// wait for the specified number of milliseconds
try { Thread.sleep (duration); } catch (Exception e) {}
// When the timer expires hide the window and get
rid of it
splash.setVisible (false);
splash = null;
}
};
r.start ();
}
public static void main (String [] args) {
showSplash (5000);
SqlManEditor s = new SqlManEditor ();
s.toBack (); // After these two lines of
code execute
splash.toFront (); // s is in front and splash
is still in back!
}
}
few seconds while the application is initialising. After a timer expires,
the splash screen will close automatically. I have all of this working just
fine.
However, at some point during the application initialisation, it creates the
main window. When this occurs, the main window appears on top of the splash
screen. I would prefer that the splash screen be "top most" when this
occurs.
I have tried various combinations of toFront() and toBack() with no success
whatsoever.
How can I keep my splash screen topmost - preferably without having to mess
with "lost focus" type of events? In VC++, I could do this by creating the
splash screen window with the "TOPMOST" attribute set - but I can't find a
similar attribute in the java window classes.
TIA - Glenn Mc
P.S. For what it is worth, I have attached some snippets of the code I am
using. SplashPanel extends JPanel and contains all of the components making
up the splash screen.
public class SqlManEditor extends JFrame {
private static JWindow splash;
private static void showSplash (final int duration) {
/* final JWindow */ splash = new JWindow ();
SplashPanel content = new SplashPanel ();
splash.setContentPane(content);
splash.pack ();
// Center the splash screen in the display.
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize ();
int x = (screen.width - content.getWidth()) / 2;
int y = (screen.height - content.getHeight()) / 2;
splash.setBounds (x, y, content.getWidth(), content.getHeight());
Thread r = new Thread () {
public void run () {
// TODO: Figure out how to get the splash screen
to be "topmost"
// Currently when the main window is
created, it will appear
// in front of the splash screen.
splash.setVisible (true);
// wait for the specified number of milliseconds
try { Thread.sleep (duration); } catch (Exception e) {}
// When the timer expires hide the window and get
rid of it
splash.setVisible (false);
splash = null;
}
};
r.start ();
}
public static void main (String [] args) {
showSplash (5000);
SqlManEditor s = new SqlManEditor ();
s.toBack (); // After these two lines of
code execute
splash.toFront (); // s is in front and splash
is still in back!
}
}