有人可以告诉我为什么我JTable
没有用下面的模型更新吗?它第一次出现很好,但是当我输入保存在数组中的新数据时int nh, string hNam, int vh, string proc_1 , string proc_2
,表不会用新数据更新。
public class TableModel extends AbstractTableModel {
int numRows;
String columnNames[] = {"NH", "Horse Names", "VH",
"Proc. I", "Proc. II"};
Object[][] myData;
TableModel() {
super();
numRows = fnh;
myData = new Object[fnh][5];
for (int i = 0; i < fnh; i++) {
for (int j = 0; j < 5; j++) {
if (j == 0) {
myData[i][0] = (Integer) nh[i];
} else if (j == 1) {
myData[i][1] = (String) hNam[i];
} else if (j == 2) {
myData[i][2] = (Integer) vh[i];
} else if (j == 3) {
myData[i][3] = (String) proc_1[i];
} else {
myData[i][4] = (String) proc_2[i];
}
}
}
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getRowCount() {
return myData.length;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public boolean isCellEditable(int row, int col) {
return true;
}
@Override
public Object getValueAt(int row, int col) {
if (col == 0) {
return nh[row];
} else if (col == 1) {
return hNam[row];
} else if (col == 2) {
return vh[row];
} else if (col == 3) {
return proc_1[row];
} else {
return proc_2[row];
}
}
@Override
public void setValueAt(Object value, int row, int col) {
myData[row][col] = value;
fireTableCellUpdated(row, col);
}
}