【发布时间】:2015-08-13 18:46:53
【问题描述】:
我知道这是初学者的问题,但它不起作用。这是代码
public void imageshow( String path ) throws IOException {
File root = new File( path );
File[] list = root.listFiles();
if (list == null) return;
for ( File f : list ) {
imageshow(f.getAbsolutePath());
if(f.getName().endsWith("jpg")||f.getName().endsWith("png")||f.getName().endsWith("gif")||f.getName().endsWith("tif"))
{
images=new ArrayList<String>();
DefaultTableModel model=new DefaultTableModel();
model.addColumn("Imya");
table.setModel(model);
model.addRow(new Vector(images));
images.add(f.getName());
image_count++;
for(String img:images)
{
System.out.println(img);
}
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
DirectoryReader fw = new DirectoryReader();
System.out.println("---Images----");
try {
fw.imageshow("D:\\Installs\\shohruh\\doc");
} catch (IOException ex) {
Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
}
}
所以,我希望在单击按钮时它应该递归地添加到我的 JTable 中。我错过了哪些细节?从逻辑上讲,我正确地编写了代码。但我没有显示在 JTable 上!请帮助解决这个问题。提前致谢
【问题讨论】:
-
源代码中的一个空白行是永远需要的。
{之后或}之前的空行通常也是多余的。
标签: java swing arraylist jtable