E - the type of the ListModel elementspublic abstract class AbstractTableAdapter<E> extends AbstractTableModel implements ListModelBindable
TableModel
interface that converts a 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 {
public CustomerTableModel() {
super("Last Name", "First Name", "Age");
}
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;
}
}
}
ListModel,
JTable,
Serialized FormlistenerList| Constructor and Description |
|---|
AbstractTableAdapter()
Constructs an AbstractTableAdapter with no ListModel set
and no predefined column names.
|
AbstractTableAdapter(ListModel listModel)
Constructs an AbstractTableAdapter on the given ListModel.
|
AbstractTableAdapter(ListModel listModel,
String... columnNames)
Constructs an AbstractTableAdapter on the given ListModel using
the specified table column names.
|
AbstractTableAdapter(String... columnNames)
Constructs an AbstractTableAdapter with the given column names.
|
| Modifier and Type | Method and Description |
|---|---|
protected ListDataListener |
createChangeHandler()
Creates and returns a listener that handles changes
in the underlying list model.
|
int |
getColumnCount()
Returns the number of columns in the model.
|
String |
getColumnName(int columnIndex)
Returns the name of the column at the given column index.
|
ListModel |
getListModel() |
E |
getRow(int index)
Returns the row at the specified row index.
|
int |
getRowCount()
Returns the number of rows in the model.
|
void |
setListModel(ListModel newListModel)
Sets the given ListModel as new underlying ListModel.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAtclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetValueAtpublic AbstractTableAdapter()
public AbstractTableAdapter(ListModel listModel)
#getColumnCount() and #getColumnName(int).listModel - the ListModel that holds the row elementspublic AbstractTableAdapter(String... columnNames)
columnNames - the predefined column namespublic AbstractTableAdapter(ListModel listModel, String... columnNames)
null, it is copied to avoid external mutation.
Subclasses that invoke this constructor with a null column
name array must override the methods #getColumnCount() and
#getColumnName(int).
listModel - the ListModel that holds the row elementscolumnNames - optional column namespublic ListModel getListModel()
getListModel in interface ListModelBindablepublic void setListModel(ListModel newListModel)
setListModel in interface ListModelBindablenewListModel - the ListModel to be setpublic int getColumnCount()
Subclasses must override this method if they don't provide an array of column names in the constructor.
getColumnCount in interface TableModelNullPointerException - if the optional column names array
has not been set in the constructor. In this case API users
must override this method.getColumnName(int),
getRowCount()public String getColumnName(int columnIndex)
Subclasses must override this method if they don't provide an array of column names in the constructor.
getColumnName in interface TableModelgetColumnName in class AbstractTableModelcolumnIndex - the index of the columnNullPointerException - if the optional column names array
has not been set in the constructor. In this case API users
must override this method.getColumnCount(),
getRowCount()public final int getRowCount()
JTable uses this method to determine how many rows it
should display. This method should be quick, as it
is called frequently during rendering.getRowCount in interface TableModelgetRow(int)public final E getRow(int index)
index - row index in the underlying list modelprotected ListDataListener createChangeHandler()
Copyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.