import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.io.File;
public class ExtendsAbstractTableModel extends AbstractTableModel
{
String []title;
Object content [][];
Class columnType[];
public ExtendsAbstractTableModel()
{
columnType=new Class[]{String.class,Number.class,Boolean.class,Boolean.class};
title=new String[]{"文件名","文件大小","可读","可写"};
this.initialContent();
}
public int getColumnCount(){
return this.title.length;
}
public int getRowCount(){
return this.content.length;
}
public Object getValueAt(int row,int col){
return content[row][col];
}
public String getColumnName(int col){
return title[col];
}
public Class getColumnClass(int col){
return columnType[col];
}
public void initialContent()
{
File tempEmptyFile=new File("\\.");
String []allFileName=tempEmptyFile.list();
content=new Object[allFileName.length][title.length];
for(int i=0;i<allFileName.length;i++)
{
File tempFile=new File(allFileName[i]);
content[i][0]=new String(tempFile.getName());
content[i][1]=new Long(tempFile.length());
content[i][2]=new Boolean(tempFile.canRead());
content[i][3]=new Boolean(tempFile.canWrite());
}
}
public static void main(String args[])
{
ExtendsAbstractTableModel myModel=new ExtendsAbstractTableModel();
JTable myJTable=new JTable(myModel);
JFrame userModel=new JFrame();
JScrollPane jsp=new JScrollPane(myJTable);
userModel.setTitle("简单的表格程序");
userModel.setBounds(100,100,450,160);
userModel.setVisible(true);
userModel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import javax.swing.*;
import javax.swing.table.*;
import java.io.File;
public class ExtendsAbstractTableModel extends AbstractTableModel
{
String []title;
Object content [][];
Class columnType[];
public ExtendsAbstractTableModel()
{
columnType=new Class[]{String.class,Number.class,Boolean.class,Boolean.class};
title=new String[]{"文件名","文件大小","可读","可写"};
this.initialContent();
}
public int getColumnCount(){
return this.title.length;
}
public int getRowCount(){
return this.content.length;
}
public Object getValueAt(int row,int col){
return content[row][col];
}
public String getColumnName(int col){
return title[col];
}
public Class getColumnClass(int col){
return columnType[col];
}
public void initialContent()
{
File tempEmptyFile=new File("\\.");
String []allFileName=tempEmptyFile.list();
content=new Object[allFileName.length][title.length];
for(int i=0;i<allFileName.length;i++)
{
File tempFile=new File(allFileName[i]);
content[i][0]=new String(tempFile.getName());
content[i][1]=new Long(tempFile.length());
content[i][2]=new Boolean(tempFile.canRead());
content[i][3]=new Boolean(tempFile.canWrite());
}
}
public static void main(String args[])
{
ExtendsAbstractTableModel myModel=new ExtendsAbstractTableModel();
JTable myJTable=new JTable(myModel);
JFrame userModel=new JFrame();
JScrollPane jsp=new JScrollPane(myJTable);
userModel.setTitle("简单的表格程序");
userModel.setBounds(100,100,450,160);
userModel.setVisible(true);
userModel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
userModel.setContentPane(jsp);多看看书上的例子……