import java.io.File;
import java.util.Date;

import javax.swing.*;
import javax.swing.table.AbstractTableModel;

public class FileTableModel extends AbstractTableModel {

  public FileTableModel(File directory) {
    files=directory.listFiles();
  }

  public int getColumnCount() {
    return 3;
  }

  public int getRowCount() {
    return files.length;
  }
  
  public String getColumnName(int column) {
    return columnNames[column];
  }

  public Object getValueAt(int row, int column) {
    File file=files[row];
    switch(column) {
      case 0:
        return file.getName();
      case 1:
        return new Long(file.length());
      case 2:
        return new Date(file.lastModified());
    }
    throw new IllegalArgumentException("invalid column ("+row+','+column+')');
  }
  
  private final File[] files;
  private final static String[] columnNames={
    "Name","Length","Last modification"
  };
  
  public static void main(String[] args) {
    FileTableModel model=new FileTableModel(new File("."));
    
    JTable table=new JTable(model);
    JScrollPane pane=new JScrollPane(table);
    
    JFrame frame=new JFrame("FileTableModel");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(pane);
    frame.setSize(400,300);
    frame.show();
  }
}