Package groovy.swing.model
Class DefaultTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
groovy.swing.model.DefaultTableModel
- All Implemented Interfaces:
Serializable,TableModel
A table model built from row and column
ValueModel instances.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classColumn model implementation that keeps model indexes aligned with the current column order. -
Field Summary
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList -
Constructor Summary
ConstructorsConstructorDescriptionDefaultTableModel(ValueModel rowsModel) Creates a table model with its own row holder.DefaultTableModel(ValueModel rowsModel, ValueModel rowModel) Creates a table model with explicit row and rows models. -
Method Summary
Modifier and TypeMethodDescriptionaddClosureColumn(Object headerValue, Closure readClosure, Closure writeClosure, Class type) Adds a closure based column to the tablevoidaddColumn(DefaultTableColumn column) Adds a new column definition to the tableaddColumn(Object headerValue, ValueModel columnValueModel) Adds a column whose header value is also used as its identifier.addColumn(Object headerValue, Object identifier, ValueModel columnValueModel) Adds a column definition with an explicit identifier.addPropertyColumn(Object headerValue, String property, Class type) Adds a property model column to the tableaddPropertyColumn(Object headerValue, String property, Class type, boolean editable) Adds a property model column to the tablegetColumnClass(int columnIndex) Returns the declared value type for the supplied column.intReturns the number of configured columns.Returns the Swing column model maintained by this table model.protected ValueModelgetColumnModel(int columnIndex) Returns the value model used by the supplied column.getColumnName(int columnIndex) Returns the header text for the supplied column.intReturns the number of rows currently exposed by the rows model.Returns the value model representing the current row object.protected ListgetRows()Returns the model that supplies the backing row collection.getValueAt(int rowIndex, int columnIndex) Reads the value for the supplied row and column.booleanisCellEditable(int rowIndex, int columnIndex) Indicates whether the supplied cell can be edited through its column model.voidremoveColumn(DefaultTableColumn column) Removes a column definition from the tablevoidsetValueAt(Object value, int rowIndex, int columnIndex) Writes a value to the supplied row and column when both coordinates are valid.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Constructor Details
-
DefaultTableModel
Creates a table model with its own row holder.- Parameters:
rowsModel- the model that supplies the row collection
-
DefaultTableModel
Creates a table model with explicit row and rows models.- Parameters:
rowsModel- the model that supplies the row collectionrowModel- the model reused for exposing the current row
-
-
Method Details
-
getColumnList
- Returns:
- the column definitions.
-
getColumnModel
Returns the Swing column model maintained by this table model.- Returns:
- the column model
-
addPropertyColumn
Adds a property model column to the table -
addPropertyColumn
public DefaultTableColumn addPropertyColumn(Object headerValue, String property, Class type, boolean editable) Adds a property model column to the table -
addClosureColumn
public DefaultTableColumn addClosureColumn(Object headerValue, Closure readClosure, Closure writeClosure, Class type) Adds a closure based column to the table -
addColumn
Adds a column whose header value is also used as its identifier.- Parameters:
headerValue- the header value and identifiercolumnValueModel- the value model used by the column- Returns:
- the created column
-
addColumn
public DefaultTableColumn addColumn(Object headerValue, Object identifier, ValueModel columnValueModel) Adds a column definition with an explicit identifier.- Parameters:
headerValue- the header valueidentifier- the column identifiercolumnValueModel- the value model used by the column- Returns:
- the created column
-
addColumn
Adds a new column definition to the table -
removeColumn
Removes a column definition from the table -
getRowCount
public int getRowCount()Returns the number of rows currently exposed by the rows model.- Returns:
- the current row count
-
getColumnCount
public int getColumnCount()Returns the number of configured columns.- Returns:
- the current column count
-
getColumnName
Returns the header text for the supplied column.- Specified by:
getColumnNamein interfaceTableModel- Overrides:
getColumnNamein classAbstractTableModel- Parameters:
columnIndex- the column index- Returns:
- the column header text, or
nullwhen unavailable
-
getColumnClass
Returns the declared value type for the supplied column.- Specified by:
getColumnClassin interfaceTableModel- Overrides:
getColumnClassin classAbstractTableModel- Parameters:
columnIndex- the column index- Returns:
- the column value type
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex) Indicates whether the supplied cell can be edited through its column model.- Specified by:
isCellEditablein interfaceTableModel- Overrides:
isCellEditablein classAbstractTableModel- Parameters:
rowIndex- the row indexcolumnIndex- the column index- Returns:
truewhen the column model is editable
-
getValueAt
Reads the value for the supplied row and column.- Parameters:
rowIndex- the row indexcolumnIndex- the column index- Returns:
- the cell value, or
nullwhen the coordinates are invalid
-
setValueAt
Writes a value to the supplied row and column when both coordinates are valid.- Specified by:
setValueAtin interfaceTableModel- Overrides:
setValueAtin classAbstractTableModel- Parameters:
value- the new cell valuerowIndex- the row indexcolumnIndex- the column index
-
getColumnModel
Returns the value model used by the supplied column.- Parameters:
columnIndex- the column index- Returns:
- the column value model
-
getRows
-
getRowModel
Returns the value model representing the current row object.- Returns:
- the current row model
-
getRowsModel
Returns the model that supplies the backing row collection.- Returns:
- the rows model
-