Sunday, 25 August 2013

How to ImageIcon Array List resize in following code

How to ImageIcon Array List resize in following code

I have ImageIcon Array list and it has many sizes of icons, So I need to
set them to a specific (85*100) size. So how I do this? my code as follow:
File file = new File("C://Users/ks/Desktop/DB");
if (file != null) {
File[] files = file.listFiles(new FilenameFilter() {
public boolean accept(File file, String fileName) {
if (fileName.endsWith(".png")) {
return true;
} else {
System.out.println("No jpg files");
return false;
}
}
});
System.out.println("Current dir : " +
file.getCanonicalPath());
List<ImageIcon> images = new ArrayList<ImageIcon>();//
Array list
for (int fileInList = 0; fileInList < files.length;
fileInList++) {
System.out.print(files[fileInList].toString() + " ");
System.out.println("this is forloop" + fileInList);
if (files[fileInList].isFile()) {
images.add(0, new ImageIcon(ImageIO.read(files[fileInList])));// add all
imagaes
}
} }
FlowLayout f = new FlowLayout();
JPanel p = new JPanel(f);
f.setAlignment(FlowLayout.LEFT);
p.setSize(700, 100);
for (int x = 0; x < images.size(); x++) {
p.add(new JLabel(images.get(x)));
}
jPanel1.setPreferredSize(p.getSize());
jPanel1.add(p);
jPanel1.revalidate();
jPanel1.repaint();
} else {
System.out.println("No file Found"); // Array index out of
bound display insted of this
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Success");

No comments:

Post a Comment