Class BeanTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
uk.ac.starlink.util.gui.BeanTableModel
- All Implemented Interfaces:
Serializable, TableModel
TableModel which displays beans.
The table is constructed to display beans of a particular class,
and each of its row displays one instance of this class.
It has one column for each readable property.
As usual, a bean is anything which has likely-looking getter methods,
though by using the
java.beans package any cleverer stuff
held in BeanInfos will get used as well/instead.
What a neat idea!- Since:
- 21 Dec 2004
- Author:
- Mark Taylor (Starlink)
- See Also:
-
Field Summary
Fields inherited from class AbstractTableModel
listenerList -
Constructor Summary
ConstructorsConstructorDescriptionBeanTableModel(Class<?> clazz) Constructs a new table model for displaying beans of a given class. -
Method Summary
Modifier and TypeMethodDescriptionClass<?> getColumnClass(int icol) intgetColumnName(int icol) Object[]getData()Returns the array of objects which this model displays, one per row.intgetValueAt(int irow, int icol) booleanisCellEditable(int irow, int icol) Comparator<?> propertySorter(String propertyName) Returns a sorter which can be used to sort rows of this table (data array elements).voidPopulates this model with items.voidsetValueAt(Object value, int irow, int icol) Methods inherited from class AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Constructor Details
-
BeanTableModel
Constructs a new table model for displaying beans of a given class.- Parameters:
clazz- class of items which will be displayed in this table- Throws:
IntrospectionException
-
-
Method Details
-
setData
Populates this model with items.- Parameters:
data- array of items, one for each row. This array's runtime type must match that for which this model was constructed (on pain of ClassCastException)
-
getData
Returns the array of objects which this model displays, one per row. The runtime type of the returned array matches that of the bean class this model displays.- Returns:
- table data
-
propertySorter
Returns a sorter which can be used to sort rows of this table (data array elements).- Parameters:
propertyName- name of readable bean property to sort on- Returns:
- a comparator that sorts on
propertyName, or null ifpropertyNamedoes not name a suitable property
-
getColumnName
- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classAbstractTableModel
-
getColumnClass
- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel
-
getColumnCount
public int getColumnCount() -
getRowCount
public int getRowCount() -
getValueAt
-
isCellEditable
public boolean isCellEditable(int irow, int icol) - Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classAbstractTableModel
-
setValueAt
- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classAbstractTableModel
-