public class MyTableModel extends AbstractTableModel{
public void setValueAt(Object value, int nRow, int nCol) {
if (nRow < 0 || nRow >= getRowCount() || value==null)
return;
MyObject row = (MyObject)m_vector.elementAt(nRow);
String svalue = value.toString();
switch (nCol) {
case 0:
row.setColOneWord(svalue);
break;
case 1:
row.setColTwoWord(svalue);
}
fireTableCellUpdated(nRow, nCol);
}
}
public void setValueAt(Object value, int nRow, int nCol) {
if (nRow < 0 || nRow >= getRowCount() || value==null)
return;
MyObject row = (MyObject)m_vector.elementAt(nRow);
String svalue = value.toString();
switch (nCol) {
case 0:
row.setColOneWord(svalue);
break;
case 1:
row.setColTwoWord(svalue);
}
fireTableCellUpdated(nRow, nCol);
}
}
构建一个model,用data[][]存放数据,
当data[][]发生变化时,自动更新table的显示,
而不是用setModel()方法来实现更新.