我正在尝试使用从驱动器目录开始创建系统文件浏览器。
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;
}
通过
设置值 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);
这是我的结果屏幕;如何显示驱动器名称?
答案 0 :(得分: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;
}