Package uk.ac.starlink.util.gui
Class BeanTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- uk.ac.starlink.util.gui.BeanTableModel
-
- All Implemented Interfaces:
java.io.Serializable
,javax.swing.table.TableModel
public class BeanTableModel extends javax.swing.table.AbstractTableModel
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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BeanTableModel(java.lang.Class clazz)
Constructs a new table model for displaying beans of a given class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Class
getColumnClass(int icol)
int
getColumnCount()
java.lang.String
getColumnName(int icol)
java.lang.Object[]
getData()
Returns the array of objects which this model displays, one per row.int
getRowCount()
java.lang.Object
getValueAt(int irow, int icol)
boolean
isCellEditable(int irow, int icol)
java.util.Comparator
propertySorter(java.lang.String propertyName)
Returns a sorter which can be used to sort rows of this table (data array elements).void
setData(java.lang.Object[] data)
Populates this model with items.void
setValueAt(java.lang.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 Detail
-
BeanTableModel
public BeanTableModel(java.lang.Class clazz) throws java.beans.IntrospectionException
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:
java.beans.IntrospectionException
-
-
Method Detail
-
setData
public void setData(java.lang.Object[] data)
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
public java.lang.Object[] 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
public java.util.Comparator propertySorter(java.lang.String propertyName)
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
public java.lang.String getColumnName(int icol)
- Specified by:
getColumnName
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnName
in classjavax.swing.table.AbstractTableModel
-
getColumnClass
public java.lang.Class getColumnClass(int icol)
- Specified by:
getColumnClass
in interfacejavax.swing.table.TableModel
- Overrides:
getColumnClass
in classjavax.swing.table.AbstractTableModel
-
getColumnCount
public int getColumnCount()
-
getRowCount
public int getRowCount()
-
getValueAt
public java.lang.Object getValueAt(int irow, int icol)
-
isCellEditable
public boolean isCellEditable(int irow, int icol)
- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
setValueAt
public void setValueAt(java.lang.Object value, int irow, int icol)
- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
-