假设我创建的Jtable名称为table,table存的是PersonItem的信息:
1.首先创建PersonItem的demo:
class PersonItem {
private String name;
private String age;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
2,,创建一个MyTableModel继承AbstractTableModel ,并重写一些方法,作为table的model:
class MyTableModel extends AbstractTableModel {
private String[] columnNames = new String[] { "num", "name", "age", "sex" };
ArrayList<PersonItem> itemList = new ArrayList<PersonItem>();
<