I have a splash screen for an an application that I am making. It is a
JWindow
JPanel
JLabel
ImageIcon
JLabel
ImageIcon
InputStream
this.getClass.getResourceAsStream("GenericApp.png");
final JWindow window = new JWindow();
JPanel jp = new JPanel();
InputStream is = this.getClass().getResourceAsStream("GenericApp.png");
Image image = null;
try {
image = ImageIO.read(is);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
JLabel l = new JLabel(new ImageIcon(image));
window.add(jp);
jp.add(l);
window.setBounds(500, 150, 300, 200);
window.setVisible(true);
try{
Thread.sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}
window.setVisible(false);
Here is how I solved it:
Apparently, the image takes a while to load. I was calling Thread.sleep(5000)
before it finished loading the image and thus cutting off the display process. The moral of the story is that you almost never want to use Thread.sleep()
USE TIMERS INSTEAD.
Regards,
Thomas