• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Repainting Panel

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic