Package uk.ac.starlink.util.gui
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 javax.swing.table.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) int
getColumnName
(int icol) Object[]
getData()
Returns the array of objects which this model displays, one per row.int
getValueAt
(int irow, int icol) boolean
isCellEditable
(int irow, int icol) Comparator<?>
propertySorter
(String propertyName) Returns a sorter which can be used to sort rows of this table (data array elements).void
Populates this model with items.void
setValueAt
(Object value, int irow, int icol) Methods inherited from class javax.swing.table.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 if propertyName does not name a suitable property
-
getColumnName
- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
-
getColumnClass
- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
-
getColumnCount
public int getColumnCount() -
getRowCount
public int getRowCount() -
getValueAt
-
isCellEditable
public boolean isCellEditable(int irow, int icol) - Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
-
setValueAt
- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
-