2014-03-28 83 views
0

我試圖創建系統文件瀏覽器,在驅動器目錄中啓動。通過AbstractTableModel不返回驅動器名稱

 public class Window { 



static class MyFrame extends JFrame implements Constants { 
    MyFrame() throws HeadlessException { 


    FileSystemTableModel model = new FileSystemTableModel(); 
    model.setFiles(File.listRoots()); 
    JTable table = new JTable(model); 

這裏

public class FileSystemTableModel extends AbstractTableModel implements 
    Constants { 

private File currentDircetory; 
private File[] files; 

@Override 
public Object getValueAt(int arg0, int arg1) { 
    switch (arg1) { 
    case 0: 
     return files[arg0].getName(); 
    case 1: 
     return files[arg0].length(); 
    case 2: 
     return new Date(files[arg0].lastModified()); 
    } 
    return arg1;  
} 

設定值是我的結果屏幕;我如何顯示驅動器名稱?

The result

+0

你要創建和發佈[小例子程序(http://stackoverflow.com/help/mcve) 。 –

回答

0

這將解決你的問題files[arg0].toString()case 0

@Override 
public Object getValueAt(int arg0, int arg1) { 
    switch (arg1) { 
     case 0: 
      return files[arg0].toString(); 
     case 1: 
      return files[arg0].length(); 
     case 2: 
      return new Date(files[arg0].lastModified()); 
    } 
    return arg1; 
} 
相關問題