Header javaperspective.com
JavaPerspective.com  >   Advanced Tutorials  >   1. Advanced GUI Features  >   1.6. Splash screens

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:


Splash screen example



There are two ways of displaying a splash screen:
  1. 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

  2. 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
    Main-Class: App
    SplashScreen-Image: images/splashScreenImage.gif

    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


You are here :  JavaPerspective.com  >   Advanced Tutorials  >   1. Advanced GUI Features  >   1.6. Splash screens
Next tutorial :  JavaPerspective.com  >   Advanced Tutorials  >   1. Advanced GUI Features  >   1.7. HTML formatting

Copyright © 2013 - 2016. JavaPerspective.com. All rights reserved.  ( Terms | Contact | About ) 
Java is a trademark of Oracle Corporation
Image 1 Image 2 Image 3 Image 4 Image 5 Image 6 Image 7