Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Repainting Panel  RSS feed

 
Matt Wil
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
maggie woo
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i do something similar, but i swap out the components in the container:
JEditorPane loading = new JEditorPane("loading...");
loading.setEnabled(false);
getContentPane().add(loading, java.awt.BorderLayout.CENTER);
javax.swing.ToolTipManager.sharedInstance().setInitialDelay(50);
// get your image ready....
getContentPane().remove(loading);
getContentPane().add(....image component...);

it may not be ideal for you, but it's an idea...
Regards,
maggie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!