Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic