Image isn't drawn as expected? SplashScreen implementation not working.

I’m having a little trouble with a splash screen here. Since I already posted to the official Java 3D forum and no one seems to know a solution, I’ll have a try here. The slightly edited text follows.

I implemented the attached simple SplashScreen class. It works fine when used alone but…

First I used my own ImageComponent class which handles image loading and component drawing itself but for reason of simplicity I switched to the ImageIcon class added to a JLabel, which yields almost the same behavior only I work with a BufferedImage in my own class.

My problem is that the component or the ImageIcon isn’t drawn immediately when the window is made visible. If you run the test method pause(), which lets the main thread sleep for 2 seconds, the component is correctly drawn AFTER this pause and not before. I added a println() call to see when
the window is set visible, expecting the image would be visible as well. Well, it isn’t. :frowning:

The same problem occurs when I instatiate my Main3D (a class extending JFrame and using a Canvas3D and a SimpleUniverse) class. First I instantiate the SplashScreen to bridge the loading time and after Main3D is completely loaded I let the program dispose the SplashScreen. Sadfully the image loaded isn’t drawn until Main3D has finished loading!

Am I missing something or is this a Swing issue? Has anyone got an idea of how to solve this problem?

  • Thomas

It would be interesting to see how you instantiate/open the splash screen?

If you’re going to use 6.0, you can use the build-in splash stuff:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/

Other than that… use a separate thread for the splash and tell it to go poof once you’re ready (over in the main thread).

Thanks for the input!

@kingaschi: The SplashScreen can be instantiated as a simple temporary object : new SplashScreen();

@oNyx: Already tried seperate threads … didn’t work as well! :frowning: The problem with the built-in spkashscreen is I’m abridging the loading time between my 2D GUI and my 3D environment with my class, something you just can’t do with Sun’s SplashScreen which is only to be used at the JVM startup. My JVM is running already so I have to go this way.

I’ll have a look at some threading again to rule out any mistakes I might have made but when I first tried it, it didn’t work.

  • Thomas