请注意,我不会以这种方式设计代码,但是我希望使它尽可能接近原始代码,同时使其能够在基于Windows的框中显示图像列表。
列表显示
import java.awt.*;import java.awt.image.BufferedImage;import javax.swing.*;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class ListView { public static void main(String[] args) throws IOException { String path = "C:/documents and Settings/All Users/documents/" + "My Pictures/Sample Pictures"; Jframe frame=new Jframe(); frame.setDefaultCloseOperation(Jframe.DISPOSE_ON_CLOSE); File folder = new File(path); File[] listOfFiles = folder.listFiles(); DefaultListModel listModel = new DefaultListModel(); int count = 0; for (int i = 0; i < listOfFiles.length; i++) { System.out.println("check path"+listOfFiles[i]); String name = listOfFiles[i].toString(); // load only JPEGs if ( name.endsWith("jpg") ) { ImageIcon ii = new ImageIcon(ImageIO.read(listOfFiles[i])); listModel.add(count++, ii); } } JList lsm=new JList(listModel); lsm.setVisibleRowCount(1); frame.add(new JScrollPane(lsm)); frame.pack(); frame.setVisible(true); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)