public final class SplashScreen extends Object
If your application is packaged in a jar file, you can use the
"SplashScreen-Image" option in a manifest file to show a splash screen.
Place the image in the jar archive and specify the path in the option.
The path should not have a leading slash.
For example, in the manifest.mf
file:
Manifest-Version: 1.0 Main-Class: Test SplashScreen-Image: filename.gif
If the Java implementation provides the command-line interface and you run
your application by using the command line or a shortcut, use the Java
application launcher option to show a splash screen. The Oracle reference
implementation allows you to specify the splash screen image location with
the -splash:
option.
For example:
java -splash:filename.gif TestThe command line interface has higher precedence over the manifest setting.
The splash screen will be displayed as faithfully as possible to present the whole splash screen image given the limitations of the target platform and display.
It is implied that the specified image is presented on the screen "as is", i.e. preserving the exact color values as specified in the image file. Under certain circumstances, though, the presented image may differ, e.g. when applying color dithering to present a 32 bits per pixel (bpp) image on a 16 or 8 bpp screen. The native platform display configuration may also affect the colors of the displayed image (e.g. color profiles, etc.)
The SplashScreen
class provides the API for controlling the splash
screen. This class may be used to close the splash screen, change the splash
screen image, get the splash screen native window position/size, and paint
in the splash screen. It cannot be used to create the splash screen. You
should use the options provided by the Java implementation for that.
This class cannot be instantiated. Only a single instance of this class
can exist, and it may be obtained by using the getSplashScreen()
static method. In case the splash screen has not been created at
application startup via the command line or manifest file option,
the getSplashScreen
method returns null
.
Modifier and Type | Method and Description |
---|---|
void |
close()
Hides the splash screen, closes the window, and releases all associated
resources.
|
Graphics2D |
createGraphics()
Creates a graphics context (as a
Graphics2D object) for the splash
screen overlay image, which allows you to draw over the splash screen. |
Rectangle |
getBounds()
Returns the bounds of the splash screen window as a
Rectangle . |
URL |
getImageURL()
Returns the current splash screen image.
|
Dimension |
getSize()
Returns the size of the splash screen window as a
Dimension . |
static SplashScreen |
getSplashScreen()
Returns the
SplashScreen object used for
Java startup splash screen control on systems that support display. |
boolean |
isVisible()
Determines whether the splash screen is visible.
|
void |
setImageURL(URL imageURL)
Changes the splash screen image.
|
void |
update()
Updates the splash window with current contents of the overlay image.
|
public static SplashScreen getSplashScreen()
SplashScreen
object used for
Java startup splash screen control on systems that support display.SplashScreen
instance, or null
if there is
none or it has already been closedUnsupportedOperationException
- if the splash screen feature is not
supported by the current toolkitHeadlessException
- if GraphicsEnvironment.isHeadless()
returns truepublic void setImageURL(URL imageURL) throws NullPointerException, IOException, IllegalStateException
imageURL
- the non-null
URL for the new
splash screen imageNullPointerException
- if imageURL
is null
IOException
- if there was an error while loading the imageIllegalStateException
- if the splash screen has already been
closedpublic URL getImageURL() throws IllegalStateException
IllegalStateException
- if the splash screen has already been closedpublic Rectangle getBounds() throws IllegalStateException
Rectangle
.
This may be useful if, for example, you want to replace the splash
screen with your window at the same location.
You cannot control the size or position of the splash screen. The splash screen size is adjusted automatically when the image changes.
The image may contain transparent areas, and thus the reported bounds may be larger than the visible splash screen image on the screen.
Rectangle
containing the splash screen boundsIllegalStateException
- if the splash screen has already been closedpublic Dimension getSize() throws IllegalStateException
Dimension
.
This may be useful if, for example,
you want to draw on the splash screen overlay surface.
You cannot control the size or position of the splash screen. The splash screen size is adjusted automatically when the image changes.
The image may contain transparent areas, and thus the reported size may be larger than the visible splash screen image on the screen.
Dimension
object indicating the splash screen sizeIllegalStateException
- if the splash screen has already been closedpublic Graphics2D createGraphics() throws IllegalStateException
Graphics2D
object) for the splash
screen overlay image, which allows you to draw over the splash screen.
Note that you do not draw on the main image but on the image that is
displayed over the main image using alpha blending. Also note that drawing
on the overlay image does not necessarily update the contents of splash
screen window. You should call update()
on the
SplashScreen
when you want the splash screen to be
updated immediately.
The pixel (0, 0) in the coordinate space of the graphics context
corresponds to the origin of the splash screen native window bounds (see
getBounds()
).
IllegalStateException
- if the splash screen has already been closedpublic void update() throws IllegalStateException
IllegalStateException
- if the overlay image does not exist;
for example, if createGraphics
has never been called,
or if the splash screen has already been closedpublic void close() throws IllegalStateException
IllegalStateException
- if the splash screen has already been closedpublic boolean isVisible()
close()
, it is also hidden automatically when
the first AWT/Swing window is made visible.
Note that the native platform may delay presenting the splash screen
native window on the screen. The return value of true
for this
method only guarantees that the conditions to hide the splash screen
window have not occurred yet.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2019, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.