Here is my code. It does not show images in the frame and instead shows some text. would anybody please suggest me that what change I should make in the code so that it allows me to show the images in a frame?
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class ListView {
public static void main(String[] args) throws IOException {
JFrame frame=new JFrame();
frame.setSize(500,500);
JLabel lbl[] = new JLabel[10];
DefaultListModel listModel;
ImageIcon[] b = new ImageIcon[10];
//JList lsm=new JList();
listModel = new DefaultListModel();
File folder = new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures");
File[] listOfFiles = folder.listFiles();
JLabel[] lb=new JLabel[15];
for (int i = 0; i < listOfFiles.length; i++)
{
System.out.println("chek panth"+listOfFiles[i].getName().toString());
// b[i] = ImageIO.read(new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/" + listOfFiles[i].getName().toString()));
b[i] = new ImageIcon("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/" + listOfFiles[i].getName().toString());
lb[i]=new JLabel(b[i]);
listModel.add(i, lb[i]);
}
JList lsm=new JList(listModel);
Component add = frame.add(new JScrollPane(lsm));
frame.setVisible(true);
}
}