kesea
asked on
Loading Images from a website taking forever.
Hi there, I have a list of images I am loading from a website, these images are all around 5kb each. When I perform a load, it seems like it takes seconds to load each image. How can I load them properly so it will load faster? This is basically what I am doing now. I am populating a JList with icons and text. The mFilename_ac variable looks like "http://www.website/picture/picture.gif". So how can I ensure the picture loads, and that it loads fast? I have put it in a thread, but it takes 60 seconds to load 100 images on a highspeed dsl? Thanks experts.
DefaultListModel dlm2 = new DefaultListModel();
URL image = new URL(mEmoticonData_t[i].mFi leName_ac. toString() );
ImageIcon myIcon_t = new ImageIcon(image);
for (int i=0; i< numImages_i; i++)
{
dlm2.addElement(new ListEntry(mEmoticonData_t[ i].mCharac ters_ac.to String(), myIcon_t));
}
emoticonList.setModel(dlm2 );
DefaultListModel dlm2 = new DefaultListModel();
URL image = new URL(mEmoticonData_t[i].mFi
ImageIcon myIcon_t = new ImageIcon(image);
for (int i=0; i< numImages_i; i++)
{
dlm2.addElement(new ListEntry(mEmoticonData_t[
}
emoticonList.setModel(dlm2
If you don't use an ImageIcon and instead load your images directly (as Image's) then they will load asynchronously.
ASKER
How do I load an image directly from a URL?
ImageIcon icon = ImageIcon(new URL("http://www.mysite.com/myimage.jpg"))
Image image = icon.getImage();
Image image = icon.getImage();
Make sure it *is* the download that's taking longer than you think it is, and not the rendering, before you try to take remedial action. For that, you'd be better leaving the code as it is (synchronous) first. You can then give objects' suggestion a try later, although it may not improve things and may even slow them down.
ASKER
Can I load the images from my .jar file or will I have to get it digitally signed?
Yes - why do you think you'd need to sign it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
URL image = getClass().getResource("/i mages/my.g if");
ImageIcon i = new ImageIcon(image);
ImageIcon i = new ImageIcon(image);
kesea - can you explain why that particular 'answer' merited the entire question points?
> can you explain why that particular 'answer' merited the entire question points?
because it will greatly speed up the loading ???
because it will greatly speed up the loading ???
Using getResource will have no effect on the loading speed whatever
> I have put it in a thread, but it takes 60 seconds to load 100 images
The second statement seems to suggest its more like 0.5 sec per image.
Can't see anything in the code that would cause it to be unnecessarily slow.