Of Splash Screens and Tips of the Day

If I ruled the world, which admittedly is probably not a good idea, software whose splash screens worked like this would be banned and its developers made to serve several months of community service as an apology.

Home > SoftwareDesign > Java

One of the things that over the years I have found irritating about Java applications is when I try to launch one and nothing happens for five seconds, ten seconds, sometimes longer. Eventually a snazzy splash screen appears. This tells me that I did click properly on the icon, menu, button, or whatever it was I did to run the thing. Of course, this has to happen one or two seconds after I have decided that I cannot not have done so, and have just repeated the action. Now I have two copies of the application starting up, slowing down the launch of the first copy even further.

After what seems like hours but is actually only a minute or so of staring at the snazzy splash screen image, the application eventually presents me with its user interface. However, before I can do anything, some applications compound the offence by displaying a modal dialogue announcing a very important tip of the day. Having wasted a minute of my life looking at a static splash screen image, I am not inclined to read the tip. Therefore, I dismiss the modal dialog without so much as a glance at it. This is a shame because the tip might actually have been useful and might have saved me many minutes in the future.

Of course, at this point, the second copy of the application finishes starting up and presents itself, whereupon I immediately close it down again to return to the user interface of the first copy.

If I ruled the world, which admittedly is probably not a good idea, software that worked like this would be banned and its developers made to serve several months of community service as an apology.

Splash Screen Strategies

Here are some very obvious strategies to use when building splash screens. Please, take note, just in case I should ever come to power.

Display the Splash Screen First

In days long gone by, when C# was just an envious green glint in Microsoft's eye, Java's Duke was a young, trim, arguably somewhat naive little chap, not the dull, over-weight, middle-aged icon that years of sitting through interminable JCP meetings have made him, and when some developers could still remember a time in their careers before they had heard of James Gosling. In those days, Java developers wrote graphical user interfaces in a lowest-common-denominator graphical toolkit called AWT. Although AWT is still part of the standard Java distribution today, Sun Microsystems introduced the Swing GUI libraries to provide a more sophisticated alternative. Unfortunately, earlier versions of Swing used to take several seconds to initialize, and for years I blamed Swing for the time it took for a Java application to display a splash screen at start up.

The solution was easy enough though. Use only AWT controls to display the splash screen. The AWTSplashScreen class described later on in this page describes how to do this.

These days, however, the difference in time between a simple splash screen written in Swing appearing and one written using only AWT seems to be insignificant. You can prove this for yourself using the SwingSplashScreen class described later. In fact, since JDK 1.6, there is even built-in support for displaying an image as a splash screen before the JVM has fully started up.

Given this, the only conclusion I can reach is that some developers are not using the built-in support in the Java Runtime Environment(JRE) for splash screens and are doing other stuff before displaying their own splash screen. Why? If you do not like the built-in option, at least display the splash screen first so users have near-instant feedback on launching the application.

Display Splash Screen Information Asynchronously

One potential excuse for not displaying a splash screen first might be a requirement to retrieve and display some snippet of information on the splash screen such as an imminent expiry of the user's license, license type, or even a copyright statement.

However, there is no reason why the splash screen cannot be displayed first and this information populated a few seconds later. Why delay the display the splash screen while you contact a license server somewhere or work out the right copyright phrase to use? After all, we may only be talking about adding one simple setter method to a splash screen class to achieve this. Both the AWT and Swing examples in the later section provide a means for displaying simple text messages while the splash screen is visible. An article ( java.sun.com ) by Oleg Semenov and Dana Nourie describes how how to do something similar for the JRE's built-in splash-screen support.

Another possible excuse for delaying the display of a splash screen might be a requirement to check a user option to see if a splash screen should be displayed or not. If it is really considered necessary to store this option in a database on a server somewhere, then admittedly this is going to be hard to workaround. However, I think it would be hard to justify such a requirement as a 'must have'. A client-side solution is preferable. Add or remove a splash screen option from the command line, for example.

Provide Progress and Status in a Splash Screen

So we have a splash screen displayed possibly with some extra information added to it after its initial appearance in the screen. Now it is just sitting there doing nothing. How do I know the application is still loading and not hung? How long should I wait before pulling the plug on it. There is always that niggling doubt in the mind of any experienced user after a static splash screen has been on display for a few seconds. The obvious answer to this one, is to display a progress bar or status message that changes every two or three seconds. This squashes that doubt and prevents the user from using the operating system to brutally terminate the start up of the application instead of waiting a bit longer.

Updating a progress bar or status message in the splash screen, There is always that niggling doubt in the mind of any experienced user after a static splash screen has been on display for a few seconds. Has the application hung? Having a progress bar or status message that changes every two or three seconds squashes that doubt and prevents the user from using the operating system to brutally terminate the start up instead of waiting a bit longer. The examples described later demonstrate a simple character string-based progress bar. A prettier, more graphically-oriented progress bar would look better, of course, but I am afraid that is left as an exercise for the reader.

Embed a Tip of the Day or Message of the Day into the Splash Screen

Displaying a frequently changing status message on the splash screen is one basic way to distract a user from the fact that your application is taking forever to load. We could go a step further, however, and instead of waiting until the application has loaded before displaying a tip of the day, display it as part of the splash screen.

Displaying a tip message in a splash screen, may compromise the artistic value of the splash screen a little but having users actually read the tip of the day as a result of doing so is probably worth it. Alternatively, use the splash screen to advertise news and events instead. Now we are treating splash screen more as a dynamic advertising space, than purely a device to let the user know the application is still loading.

There is, of course, one big disadvantage to displaying tips in a splash screen. The application could finish loading and the splash screen disappear while the user is half-way through reading a tip or message. For some of the applications I use, this seems unlikely unless the tip is particularly long or complex, or the user was distracted and did not start reading the tip until the application had almost finished starting up. However, it is probably best to show a title or teaser for the tip or message and request the user to press a button to view the rest of the tip. If the user presses the button, we do not automatically hide the splash screen when the application has finished loading, instead we enable a close button for the user to click when they have finished reading the tip.

The SimpleSwingTipSplashScreen class described below provides an example.

Provide a Means to Abort the Loading of the Main Application

This is for those users like myself who start up an application and then, for example, discover their train is about is about to pull into their station, or boarding is announced for their flight. We need to shut down their laptop computers quickly and cleanly but we cannot because the application is still loading. It is also for users, again like myself, who somehow manage to start two or even three instances of the application loading.

We provide a button of some sort on the splash screen to abort the start up of the application. It does not have to be a big, gaudy thing that destroys the beauty of the marketing-provided splash screen image.

Pressing the button is, of course, not going to simply kill the main process. The likelihood is that when the abort button is hit, the splash screen simply sets a flag. The main start up thread must inspect the flag every now and then and abort the start up gracefully if the flag is set. Of course, the final thing the main thread does on shutting down is remove the splash screen.

The SwingTipSplashScreen class described below supports this.

My Java Attic

The following are some related Java classes discovered on some remote regions of my backup drive, dusted off a little, and presented mainly for posterity but also in case someone might find them useful in some way.

The AWTSplashScreen Class

The class, com.step10.simplesplashscreen.AWTSplashScreen (in the JavaAttic.zip file) demonstrates that a simple splash screen can be created and displayed almost instantaneously using AWT components.The com.step10.examples.SimpleAWTSplashScreenExample class shows how to use it

Extending java.awt.Frame, the class has a single constructor that displays an image loaded from a file above two text labels. Parameters for the constructor enable the file containing the image, and initial text, foreground and background colours for the two labels to be specified.

The constructor uses instances of the java.awt.Toolkit and Canvas classes to load the image from the file. The actual loading is encapsulated in a class called ImageCanvas, adapted from an example in Geary, McClellam, Graphic Java 1.1: Mastering the AWT, Prentice Hall Ptr.

Once the image is loaded, the label controls are constructed. The three controls are then added to a new instance of java.awt.Window using a mix of java.awt.Panel and java.awt.BorderLayout (my favourite layout manager) objects. The setVisible() and dispose() operations of java.awt.Frame are overridden to display the new Window object while leaving the actual frame invisible. The only other bits and pieces in the class are a private method to dress the label controls, and a couple of modifier methods to enable the text of the two labels to be changed as appropriate.

The com.step10.examples.SimpleAWTSplashScreenExample class provides an example of how to build and display the splash screen. It displays the splash screen for ten seconds, populating the two labels with different information simulating the progress of a major application starting up and the display of additional information retrieved from a mythical server somewhere.

The splash screen would benefit from a more graphical display of progress such as one of those lumpy percentage-complete bars, or the kind of progress bar that updates smoothly but on reaching the end simply starts again from the beginning. However, that is not going to happen because there is no longer any need to restrict ourselves to AWT. The difference now in time between a simple splash screen written in Swing appearing and one written using only AWT is insignificant on my very ordinary laptop computer.

The SwingSplashScreen Class

Building a Splash screen using Swing is easier than doing so with AWT. Extending javax.swing.JFrame, the com.step10.simplesplashscreen.SwingSplashScreen class (in the JavaAttic.zip file) is similar to its AWT-only counterpart. It uses an instance of the javax.swing.ImageIcon class instead of the supporting ImageCanvas class to load an image, and javax.swing.JLabel objects are used instead of java.awt.Label objects. The Swing version does not need a separate Window object in which to display the splash screen. Instead it displays the splash screen contents in the content pane of the JFrame and sets the frame to be undecorated.

Again there seems little point in doing anything more with this class because we have an even simpler way. Since JDK 1.6, there is built-in support for displaying an image as a splash screen before the JVM has started up. The image is either specified on the java command line or in the manifest of the application's jar file. The java.awt.SplashScreen class provides access to this image.

The SwingTipSplashScreen Class

This class from the JavaAttic.zip file embeds a tip of the day display inside a splash screen. Again the class extends javax.swing.JFrame. There are probably several different ways of embedding a tip of the day into a splash screen image. In this example, I have chosen to break the image into five sections that match the areas in a java.awt.BorderLayout. Then, when ready, I can replace the central section with an instance of the com.step10.tipsplashscreen.SwingTipPanel class to show the tip of the day content.

The example makes use of ResourceBundle objects to provide the titles and content of the tips displayed plus the label, button and associated tool tip text.

If the user clicks on any of the buttons in the button bar below the tip, a flag is set in the SwingTipPanel class to indicate that the user is interacting with the content, and the splash screen should not automatically disappear once the application has finished loading.

While the application is loading, the stop button may be pressed to signal that the loading process should be aborted. Once the application has loaded, if the user is reading the tip content, this button is replaced by a close button (actually the same button is 're-purposed'). The user dismisses the splash screen once they have finished reading the tips by pressing this close button.

Copyright 2010 Stephen R. Palmer. All rights reserved.