"Glenn McCall" <> wrote in message
news:...
>
> > Post complete working code and I'll have a look at it!
>
> No problem. I can't post the complete code but here is a cut down version
> that does the same thing.
Now we're cookin' with gas (is very good stuff)
Well, I was not able to solve the question of
why it did not work your way, but I have come
up with a rather 'hackish' fix that works for the
1.4.2 JVM on XP.
Maybe Alex or others wiil come up with
a better solution..
_______________________________________
import javax.swing.*;
import java.awt.*;
class SplashPanel extends JPanel {
public SplashPanel () {
setLayout (new BoxLayout (this, BoxLayout.Y_AXIS));
setBounds (0, 0, 240, 120);
add (new JLabel ("A really really really wide splash screen."));
add (new JLabel ("So wide so that it hopefully will show under " +
"the main window."));
add (new JLabel ("And a few JLabels so that it will have a " +
"little height"));
setBackground (Color.WHITE);
setOpaque (true);
}
}
/*-------------------------------------------------------------
Next the SqlManEditor
//-------------------------------------------------------------
*/
public class SqlManEditor extends JFrame {
public SqlManEditor () {
// Simulates initialisation activity in main thread.
// Moving this activity to after the setVisible (true)
// doesn't help much either.
try { Thread.sleep (500); } catch (Exception e) {}
pack ();
// You may need to adjust this to get the splash screen to overlap
// the main window.
setSize (200, 300);
// Code borrowed from showSplash to try
// and force the two windows to overlap.
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize ();
int x = (screen.width - getWidth()) / 2;
int y = (screen.height - getHeight()) / 2;
setBounds (x, y, getWidth(), getHeight());
setVisible (true);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
// splash.toFront ();
if ( splash.getFocusableWindowState() )
{
splash.requestFocus();
splash.hide();
splash.show();
// splash.toFront ();
System.out.println("Window to front!");
}
else System.out.println("Window is not focusable!");
// Putting the initialisation workload here after the setVisible (true)
// doesn't seem to help either.
}
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 ();
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 a little while
try { Thread.sleep (duration); } catch (Exception e) {}
splash.setVisible (false);
splash = null;
}
};
r.start ();
}
public static void main (String [] args) {
showSplash (10000);
SqlManEditor s = new SqlManEditor ();
// s.toBack ();
}
}
___________________________________
HTH
--
Andrew Thompson
*
http://www.PhySci.org/ PhySci software suite
*
http://www.1point1C.org/ 1.1C - Superluminal!
*
http://www.AThompson.info/andrew/ personal site