姬長信(Redy)

java – 将带有图像的JLabel添加到JList以显示…


这是我的代码.它不会在框架中显示图像,而是显示一些文本.任何人都可以建议我,我应该在代码中做出什么改变,以便它允许我在一个框架中显示图像?
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