Package com.portal.browse
Class ListTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
com.portal.browse.ListTableModel
- All Implemented Interfaces:
Serializable
,TableModel
- Direct Known Subclasses:
ListTableSorter
A table model the uses the List object from the collections api. The
data is stored in a list of lists. By default, this model will use
ArrayList if one is not provided in the constructor
- Version:
- %version%
- Author:
- Monica Gaines
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a table model with zero rows and columns.ListTableModel
(List data) Constructs a table model and initializes the data to the given data list.ListTableModel
(List data, List headers) Constructs a table model and initializes the data to the given data list and the headers to the given header list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a column to the model.void
Insert the given row to at the specified location in the model.void
Add the given row to the end of the model.void
addRowBatch
(List rowData) Add the given batch of rows to the end of the model.getColumnClass
(int col) Used to determine the default renderer/editor for each cell.int
Returns the number of columns in the model.getColumnName
(int col) Returns the column name from the given column.getDataAt
(int row) Returns a list of data at the given row.Returns a List of Lists that contains the data for the table.int
Returns the number of rows in the model.getValueAt
(int row, int col) Returns a value for the cell at the given row and column.boolean
isCellEditable
(int row, int col) void
removeRow
(int row) Remove the given row from the model.void
setDataList
(List data) Replace the current data list with the given list.void
setHeaderList
(List headers) Replace the current header list with the given list.void
setValueAt
(Object val, int row, int col) Sets the value for the cell at the given row and column.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Field Details
-
dataList
-
headerList
-
-
Constructor Details
-
ListTableModel
public ListTableModel()Constructs a table model with zero rows and columns. -
ListTableModel
Constructs a table model and initializes the data to the given data list.- Parameters:
data
- the data for the model
-
ListTableModel
Constructs a table model and initializes the data to the given data list and the headers to the given header list.- Parameters:
data
- the data for the modelheaders
- the column headers for the model
-
-
Method Details
-
isCellEditable
public boolean isCellEditable(int row, int col) - Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
-
getRowCount
public int getRowCount()Returns the number of rows in the model.- Returns:
- the number of rows in the model
-
getColumnCount
public int getColumnCount()Returns the number of columns in the model.- Returns:
- the number of columns in the model
-
getColumnName
Returns the column name from the given column.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
col
- the column whose name is to be looked up- Returns:
- the string value for this column.
-
getValueAt
Returns a value for the cell at the given row and column.- Parameters:
row
- the row whose value is to be looked upcol
- the column whose value is to be looked up- Returns:
- the value of the object at the given cell
-
getDataAt
Returns a list of data at the given row.- Parameters:
row
- the row whose dat is to be looked up- Returns:
- the list of data at the given row
-
getDataList
Returns a List of Lists that contains the data for the table. The outer list corresponds to a single row of data.- Returns:
- the table data
-
setValueAt
Sets the value for the cell at the given row and column. This method will generate a tableChanged notification.- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
val
- the new value for the given cellrow
- the row whose value is to be changedcol
- the column whose value is to be changed
-
getColumnClass
Used to determine the default renderer/editor for each cell.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
-
setDataList
Replace the current data list with the given list. This method will generate a tableChanged notification.- Parameters:
data
- the new data list
-
setHeaderList
Replace the current header list with the given list. This method will generate a table structure changed notification.- Parameters:
headers
- the new header list
-
addColumn
Add a column to the model. This method will generate a table structure change notification. -
addRow
Add the given row to the end of the model. This method will generate a tableChanged notification.- Parameters:
rowData
- the row being added
-
addRow
Insert the given row to at the specified location in the model. This method will generate a tableChaned notification.- Parameters:
row
- the index where the row is to be insertedrowData
- the row being added
-
addRowBatch
Add the given batch of rows to the end of the model. This method will generate a tableChaned notification.- Parameters:
rowData
- mutliple rows of data
-
removeRow
public void removeRow(int row) Remove the given row from the model. This method will generate a table rows deleted notification.- Parameters:
row
- the index of the row to be removed
-