JAVA菜鸟写的一个图片缩略图..希望帮忙添加一个滚动条..publicclassdemotestextendsJFrame{publicdemotest(Strings){Containercontainer=getContentPane();container.setLayout(newFl...
JAVA菜鸟写的一个图片缩略图..希望帮忙添加一个滚动条..
public class demotest extends JFrame{
public demotest(String s){
Container container = getContentPane();
container.setLayout(new FlowLayout(FlowLayout.LEFT));
// container.add(new JScrollPane());
File file = new File(s);
String[] picture = file.list();
int j,k;
int[] flag = new int[picture.length];
for(k = 0,j = 0;j < picture.length;j++) {
if(picture[j].toLowerCase().endsWith(".jpg") || picture[j].toLowerCase().endsWith(".jpeg") || picture[j].toLowerCase().endsWith(".gif")
|| picture[j].toLowerCase().endsWith(".png")){
k++;
//System.out.println(picture[j]);
}
}
String[] pic = new String[k];
for(k = 0,j = 0;j < picture.length;j++) {
if(picture[j].toLowerCase().endsWith(".jpg") || picture[j].toLowerCase().endsWith(".jpeg") || picture[j].toLowerCase().endsWith(".gif")
|| picture[j].toLowerCase().endsWith(".png")){
pic[k] = s + "\\" + picture[j];
flag[k] = j;
k++;
}
}
for(int i = 0;i < pic.length;i++){
ImageIcon a = new ImageIcon(pic[i]);
Image b = a.getImage();
JLabel label = new JLabel(new ImageIcon(b.getScaledInstance(250,170,Image.SCALE_DEFAULT)));
JLabel label2 = new JLabel(picture[flag[i]],JLabel.CENTER);
JPanel jpanel = new JPanel();
jpanel.setLayout(new BorderLayout());
jpanel.add(label,BorderLayout.CENTER);
jpanel.add(label2,BorderLayout.SOUTH);
JScrollPane c = new JScrollPane();
c.setViewportView(jpanel);
container.add(c);
}
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(800,660);
this.setVisible(true);
}
public static void main(String[] args){
demotest demo = new demotest("D:\\22");(自己添加路径试试程序)
}
}
这是一个类似于ACDSEE左边显示的图片缩略图,不过粗糙很多就是了,只是想在图片多的时候,显示不了那么多图片,要添加滚动条.. 加分不是问题...先谢谢大家...
展开