写一个最简单的例子做参考吧
import java.awt.borderlayout;
import java.awt.container;
import java.awt.dimension;
import javax.swing.jframe;
import javax.swing.jtable;
import javax.swing.table.defaulttablemodel;
public class jtabletest extends jframe {
private jtable table;
private defaulttablemodel model;
private object[] header={"1","2","3"};
private object[][] data={{"sdf",new integer(1),new boolean(false)},{"abc",new integer(2),new boolean(true)}};
public jtabletest()
{
initcomponent();
this.setminimumsize(new dimension(300,300));
this.setlocationrelativeto(null);
this.setdefaultcloseoperation(jframe.exit_on_close);
}
private void initcomponent()
{
container content=this.getcontentpane();
model=new defaulttablemodel(data,header){
public class> getcolumnclass(int columnindex) {
return getvalueat(0, columnindex).getclass();
}
};
table=new jtable(model);
content.add(table.gettableheader(),borderlayout.north);
content.add(table);
}
public static void main(string[] args) {
new jtabletest().setvisible(true);
}
}