class MyTableModel extends AbstractTableModel {
private String[] columnNames = ...//same as before...
private Object[][] data = ...//same as before...
public int getColumnCount() {
return columnNames.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
/*
* Don't need to implement this method unless your table's
* editable.
*/
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col < 2) {
return false;
} else {
return true;
}
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
...
}
All this code is from the Oracle tutorial, and it is pretty much all there is to using
AbstractTableModel.
The could should be made clearer with the @Override annotation to show that all those methods are inherited.
setRowCount() etc are just meta data which need to be filled in.
The area concerned with setting cell data is setValueAt(), where you update the data, then update the table using the inherited fireTable methods, which you do not need to fill in or alter.
If you still don't get it, or have more specific issues, please say so.