This Java tutorial chapter explain you how to create and implement the splash screen using Java Swing. The Java Swing splash screen indicates the user that something is happening in the application for the certain amount of time. We have used sleep() method of Thread class to create a swing splash screen in Java. The Java splash screen will get disappeared on its own after the specific amount of time.
Here is the code:
import javax.swing.*;
public class SplashScreen {
public static void main(String[] arg) {
JWindow window = new JWindow();
window.getContentPane().add(
new JLabel("Loading JFrame...", SwingConstants.CENTER));
window.setBounds(200, 200, 200, 100);
window.setVisible(true);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
window.setVisible(false);
JFrame frame = new JFrame();
frame.add(new JLabel("Welcome"));
frame.setVisible(true);
frame.setSize(300, 100);
window.dispose();
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.