To print messages on the splash screen, you need to add a picture to your application and add it to the manifest.mf:
SplashScreen-Image: path/picture.jpg
Then use code like this:
private static Graphics2D splashGraphics = null;
private static SplashScreen splash;
private static int dpi;
public static void main(String[] args) {
initSplashMessages();
splashMessage("Start program...");
...
splashMessage("Load data...");
...
}
private static void initSplashMessages() {
splash = SplashScreen.getSplashScreen();
if (splash == null) return;
splashGraphics = splash.createGraphics();
if (splashGraphics == null) return;
dpi = Toolkit.getDefaultToolkit().getScreenResolution();
}
public static void splashMessage(String message) {
if (splashGraphics == null) return;
Dimension dim = splash.getSize();
splashGraphics.setColor(Color.LIGHT_GRAY);
splashGraphics.fillRect(0, dim.height - dpiX(20), dim.width, dpiX(20));
splashGraphics.setPaintMode();
splashGraphics.setColor(Color.BLACK);
splashGraphics.setFont(new Font("Arial",Font.PLAIN, dpiX(12)));
splashGraphics.drawString(message, dpiX(3), dim.height - dpiX(5));
splash.update();
}
private static int dpiX(int x) {
return (int) Math.round(1.0 * x * dpi / 96);
}
In IntelliJ add the picture.jpg to your project (use File):
For debugging use "Modify options"/"Add VM options" and write
-splash:path/picture.jpg
Thread.sleep(3000);
– Remorseful