public class TableModel<V> extends Object
TableModel
contains the data model behind a table, here is where all the action cell values and header
labels are stored.Modifier and Type | Class | Description |
---|---|---|
static interface |
TableModel.Listener<V> |
Listener interface for the
TableModel class which can be attached to a TableModel to be notified
of changes to the table model. |
Constructor | Description |
---|---|
TableModel(String... columnLabels) |
Default constructor, creates a new model with same number of columns as labels supplied
|
Modifier and Type | Method | Description |
---|---|---|
TableModel<V> |
addColumn(String label,
V[] newColumnValues) |
Adds a new column into the table model as the last column.
|
TableModel<V> |
addListener(TableModel.Listener<V> listener) |
Adds a listener to this table model that will be notified whenever the model changes
|
TableModel<V> |
addRow(Collection<V> values) |
Adds a new row to the table model at the end
|
TableModel<V> |
addRow(V... values) |
Adds a new row to the table model at the end
|
TableModel<V> |
clear() |
Removes all rows from the table, this will trigger listeners for each row
|
V |
getCell(int columnIndex,
int rowIndex) |
Returns the cell value stored at a specific column/row coordinate.
|
int |
getColumnCount() |
Returns the number of columns in the model
|
String |
getColumnLabel(int index) |
Returns the label of a column header
|
List<String> |
getColumnLabels() |
Returns all column header label as a list of strings
|
List<V> |
getRow(int index) |
Returns a row from the table as a list of the cell data
|
int |
getRowCount() |
Returns number of rows in the model
|
List<List<V>> |
getRows() |
Returns all rows in the model as a list of lists containing the data as elements
|
TableModel<V> |
insertColumn(int index,
String label,
V[] newColumnValues) |
Adds a new column into the table model at a specified index.
|
TableModel<V> |
insertRow(int index,
Collection<V> values) |
Inserts a new row to the table model at a particular index
|
TableModel<V> |
removeColumn(int index) |
Removes a column from the table model
|
TableModel<V> |
removeListener(TableModel.Listener<V> listener) |
Removes a listener from this model so that it will no longer receive any notifications when the model changes
|
TableModel<V> |
removeRow(int index) |
Removes a row at a particular index from the table model
|
TableModel<V> |
setCell(int columnIndex,
int rowIndex,
V value) |
Updates the call value stored at a specific column/row coordinate.
|
TableModel<V> |
setColumnLabel(int index,
String newLabel) |
Updates the label of a column header
|
public TableModel(String... columnLabels)
columnLabels
- Labels for the column headerspublic int getColumnCount()
public int getRowCount()
public List<List<V>> getRows()
public List<String> getColumnLabels()
public List<V> getRow(int index)
index
- Index of the row to returnpublic TableModel<V> addRow(V... values)
values
- Data to associate with the new row, mapped column by column in orderpublic TableModel<V> addRow(Collection<V> values)
values
- Data to associate with the new row, mapped column by column in orderpublic TableModel<V> insertRow(int index, Collection<V> values)
index
- Index the new row should have, 0 means the first row and row count will append the row at the
endvalues
- Data to associate with the new row, mapped column by column in orderpublic TableModel<V> removeRow(int index)
index
- Index of the row to removepublic TableModel<V> clear()
public String getColumnLabel(int index)
index
- Index of the column to retrieve the header label forpublic TableModel<V> setColumnLabel(int index, String newLabel)
index
- Index of the column to update the header label fornewLabel
- New label to assign to the column headerpublic TableModel<V> addColumn(String label, V[] newColumnValues)
newColumnValues
.label
- Label for the header of the new columnnewColumnValues
- Optional values to assign to the existing rows, where the first element in the array will
be the value of the first row and so on...public TableModel<V> insertColumn(int index, String label, V[] newColumnValues)
newColumnValues
.index
- Index for the new columnlabel
- Label for the header of the new columnnewColumnValues
- Optional values to assign to the existing rows, where the first element in the array will
be the value of the first row and so on...public TableModel<V> removeColumn(int index)
index
- Index of the column to removepublic V getCell(int columnIndex, int rowIndex)
columnIndex
- Column index of the cellrowIndex
- Row index of the cellpublic TableModel<V> setCell(int columnIndex, int rowIndex, V value)
columnIndex
- Column index of the cellrowIndex
- Row index of the cellvalue
- New value to assign to the cellpublic TableModel<V> addListener(TableModel.Listener<V> listener)
listener
- TableModel.Listener
to register with this modelpublic TableModel<V> removeListener(TableModel.Listener<V> listener)
listener
- TableModel.Listener
to deregister from this modelCopyright © 2020. All rights reserved.