An abstract implementation of the
javax.swing.table.TableModel interface that converts a
javax.swing.ListModel of row elements.
This class provides default implementations for the TableModel
methods #getColumnCount() and #getColumnName(int) .
To use these methods you must use the constructor that accepts an
array of column names and this array must not be null .
If a subclass constructs itself with the column names set to null
it must override the methods #getColumnCount() and
#getColumnName(int) .
Example: API users subclass AbstractTableAdapter
and just implement the method TableModel#getValueAt(int, int) .
The following example implementation is based on a list of customer rows
and exposes the first and last name as well as the customer ages:
public class CustomerTableModel extends AbstractTableAdapter {
private static final String[] COLUMN_NAMES =
{ "Last Name", "First Name", "Age" };
public CustomerTableModel(ListModel listModel) {
super(listModel, COLUMN_NAMES);
}
public Object getValueAt(int rowIndex, int columnIndex) {
Customer customer = (Customer) getRow(rowIndex);
switch (columnIndex) {
case 0 : return customer.getLastName();
case 1 : return customer.getFirstName();
case 2 : return customer.getAge();
default: return null;
}
}
}
author: Karsten Lentzsch version: $Revision: 1.8 $ See Also: javax.swing.ListModel See Also: javax.swing.JTable< Parameters: E - > the type of the ListModel elements |