1.6. Splash screens
Last updated: 1 January 2013.
This tutorial will show you how to use splash screens in Java.
A splash screen is an image contained in an undecorated frame that pops up (before the JVM starts) to indicate that an application is starting up. When the application starts up and displays its main frame, the splash screen is automatically hidden. You can display a GIF, JPEG or PNG file in a splash screen. The displayed image can be animated. Here is an example:
There are two ways of displaying a splash screen:
- With a command line option: You must specify the location of the splash screen image with the -splash option. For example, if the class containing the main method that starts your application is named App and the image file is images/splashScreenImage.gif, the command is the following:java -splash:images/splashScreenImage.gif App
- With a JAR file: If you want to bundle in a JAR file the class files and resources of your application (including the splash screen image), you can use the SplashScreen-Image option to specify the path of the splash screen image.
First, create a custom manifest file named customManifest.txt that specifies a splash screen image. That custom manifest file must end with a new line. Here is its content:Manifest-Version: 1.0
Next, create the jar file with the following command:
jar cfm resultingJarFile.jar customManifest.txt images/splashScreenImage.gif inputFilesList
In the above command, resultingJarFile.jar is the name of the generated JAR file and inputFilesList is a list of files and/or directories separated by spaces. The options f and m must be in the same order as the arguments resultingJarFile.jar and customManifest.txt.
To finish, start the application with this command:
java -jar resultingJarFile.jar