Skip to main content

Splash Screen

Posted by evanx on April 25, 2007 at 1:44 AM PDT

If it's gonna take a while to start up our Swing app, then we probably wanna
display a splash screen.

It's easy with Java6 - just add a -splash command-line option.


href="https://aptframework.dev.java.net/gooey/splashScreen.html">
align="left" hspace="8"/>

Click here to read "Splash Screen, a waiting game"

A part of "Gooey Beans, the GUI part of a trilogy in 42 parts"

style="text-decoration: none;">



Code Snippet

We initialise a SplashScreen instance and get its Graphics2D as follows.

public class SplashTest {
    static Logger logger = Logger.getLogger(SplashTest.class.getSimpleName());
    final SplashScreen splash = SplashScreen.getSplashScreen();
    Rectangle splashBounds;
    Graphics2D splashGraphics;
   
    protected void initSplash() throws Exception {
        if (splash == null) {
            throw new Exception("no splash image specified eg. -splash:mysplash.png");
        }
        splashBounds = splash.getBounds();
        splashGraphics = (Graphics2D) splash.createGraphics();
        ...
    }
   
    protected void updateSplash(String status, int progress) {
        if (splash == null) return;
        drawSplash(splashGraphics, status, progress);
        splash.update();
    }
    ...
}   

where in drawSplash() we draw a progress bar ourselves over the splash image
using the Graphics2D instance.


style="text-decoration: none;">
style='text-decoration: none;'>
style="text-decoration: none;">
Related Topics >>