Reputation: 1519
I need to show a splash screen on button click. When I click the button the splash has to be visible, I do some process which runs on the background. After the background process finishes, the splash has to disappear. I used the following code, but the splash doesn't visible. When I use the same code in main class, it works.
btnClickToMove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
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();
}
// my process which runs on background.......
window.setVisible(false);
window.dispose();
}
});
Upvotes: 1
Views: 326
Reputation: 168825
Don't perform long running tasks on the EDT. Use a SwingWorker, and see Concurrency in Swing for more details.
Upvotes: 1