I use this code. Maybe you need to change some parts:
import javax.swing.*;
import java.awt.*;
public class SplashScreen {
private final JWindow window;
private long startTime;
private int minimumMilliseconds;
public SplashScreen() {
window = new JWindow();
var image = new ImageIcon("C:\\example.jpg");
window.getContentPane().add(new JLabel("", image, SwingConstants.CENTER));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
window.setBounds((int) ((screenSize.getWidth() - image.getIconWidth()) / 2),
(int) ((screenSize.getHeight() - image.getIconHeight()) / 2),
image.getIconWidth(), image.getIconHeight());
}
public void show(int minimumMilliseconds) {
this.minimumMilliseconds = minimumMilliseconds;
window.setVisible(true);
startTime = System.currentTimeMillis();
}
public void hide() {
long elapsedTime = System.currentTimeMillis() - startTime;
try {
Thread.sleep(Math.max(minimumMilliseconds - elapsedTime, 0));
} catch (InterruptedException e) {
e.printStackTrace();
}
window.setVisible(false);
}
}
And here is how to use it:
var splash = new SplashScreen();
splash.show(2000);
// Initializing...
splash.hide();
This will show the splash at least 2 seconds.