posted 19 years ago
Hi,
I have a JPanel where I am trying to display a JLabel(named loading) that displays the text "Loading..." while I am waiting for a jpeg to load. When the image is done loading, I want it to display the image, and then remove the JLabel that displays "Loading...". This doesnt work however.. my code seems to display the text, hide it and display that image all at once. You never see the Loading text. My code is below. Will my mutliple calls to repaint not work as intended?
void loadAdSelectPreview(){
//display text "Loading..."
adDownloaded=false;
loading.setVisible(true);
repaint();
//display Image, hiding "Loading..."
try {
URL url = new URL("http://www.example.com/AdMakerApp/ImageData/" +
AdMakerApp.adPreviewObject.getAdFilename() + ".jpg");
imgIcon = new ImageIcon(url);
img = imgIcon.getImage();
}catch(Exception e) { }//change to specific exception later
adDownloaded=true;
loading.setVisible(false);
repaint();
}