Loading too much images cause some problems
Hi,
I try to load multiple images from the file chooser. And display it in JScrollPane. I do repaint(); and validate(); inside my actionPerformed(); I am not too sure of these two functions actually. But I thought it should repaint the background after loading each image. In fact when I try to load 100s of images, it tooks quite along time to see the images in the JScrollPane and all the images are displayed at once. I wish to know if there's anyway to update the display after each image has been loaded. So that at least I can give the user the hint that the images are still loading.
Here's my problem code
publicvoid actionPerformed(ActionEvent e){
if (e.getSource() == BtnBrowse){
int returnVal = fcSelectFile.showDialog(this,"Select");
if (returnVal == JFileChooser.APPROVE_OPTION){
File file[]= fcSelectFile.getSelectedFiles();
//This is where a real application would open the file.
int count=0;
//PnlUpload.removeAll();
JLabel selectedFile[]=new JLabel[file.length];
while(count<file.length)
{
String actualFile=file[count].toString();
String fileName= file[count].getName();
selectedFile[count]=new JLabel(createImageIcon(actualFile,fileName));
PnlImageHolder.add(selectedFile[count]);
PnlImageHolder.repaint();
PnlImageHolder.validate();
count++;
}
ScpImageScroller.getViewport().add(PnlImageHolder);
}else{
log.append("Open command cancelled by user.\n");
}
}
}
//Here i get the images and resize it
protectedstatic ImageIcon createImageIcon(String path,
String description){
//java.net.URL imageURL = FotoUpload.class.getResource(path);
String imageURL = path;
if (imageURL ==null){
System.err.println("Resource not found: "
+ path);
returnnull;
}else{
ImageIcon icon=new ImageIcon(imageURL);
Image img=icon.getImage();
int width=img.getWidth(null);
int height=img.getHeight(null);
if(width>height)
{width=120;
height=90;
}
else
{width=90;
height=120;
}
Image thumbnail=img.getScaledInstance(width,height,java.awt.Image.SCALE_SMOOTH);
returnnew ImageIcon(thumbnail, description);
}
}

