ArrayListTableModelpublic abstract class ArrayListTableModel extends AbstractTableModel JTable model for ArrayList of heterogeneous objects.
Subclasses must set String columnNames[] and
Class columnClasses[], which MUST be in the same order.
Subclasses need only implement these AbstractTableModel methods:
public int getColumnCount() {
public Object getValueAt(int row, int col) {
public void setValueAt(Object val, int row, int col) {
|
Fields Summary |
---|
protected String[] | columnNamesList of column names, must be provided by subclass. | protected Class[] | columnClassesList of column names, must be provided by subclass. | protected ArrayList | mThe list of Method object | private int | ROW_INVALIDfor caching. | private int | prevRowfor caching, shared by get/set ValueAt | private Object | currentfor caching, shared by get/set ValueAt |
Constructors Summary |
---|
public ArrayListTableModel(ArrayList m)Constructor requires the list of objects
this.m = m;
|
Methods Summary |
---|
public java.lang.Object | getCached(int row)Cache one most-recently-used item. This is a convenience
routine that subclasses are invited but not required to use.
Normal use would be, in get/setValueAt():
public void setValueAt(int row, ...) {
MyDataType current = (MyDataType) getCached(row);
...
}
if (row != prevRow) {
current = m.get(row);
prevRow = row;
}
return current;
| public java.lang.Class | getColumnClass(int n)Get the class of a given column, from the list provided by subclass
if (columnClasses == null)
throw new IllegalStateException("columnClasses not set");
int max = columnClasses.length;
if (n>=max)
throw new ArrayIndexOutOfBoundsException(
"columnClasses has " + max + " elements; you asked for " + max);
return columnClasses[n];
| public java.lang.String | getColumnName(int n)Get the name of a given column, from the list provided by subclass
if (columnNames == null)
throw new IllegalStateException("columnNames not set");
int max = columnNames.length;
if (n>=max)
throw new ArrayIndexOutOfBoundsException(
"columnNames has " + max + " elements; you asked for " + max);
return columnNames[n];
| public int | getRowCount()Returns the number of objects in the list.
return m.size();
| public void | invalidateCache()Invalidate the cache. Called automatically by setListData();
must be called if you otherwise change the ArrayList.
prevRow = ROW_INVALID;
| public boolean | isCellEditable(int rowIndex, int columnIndex)All cells are editable.
Subclasses can override this if only some cells should be editable.
return true;
| void | setListData(java.util.ArrayList v)Allow the model to load the ArrayList all at once, as when
loading a file.
m = v;
invalidateCache();
|
|