Class TableModel<V>
java.lang.Object
com.googlecode.lanterna.gui2.table.TableModel<V>
A
TableModel contains the data model behind a table, here is where all the action cell values and header
labels are stored.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener interface for theTableModelclass which can be attached to aTableModelto be notified of changes to the table model. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTableModel(String... columnLabels) Default constructor, creates a new model with same number of columns as labels supplied -
Method Summary
Modifier and TypeMethodDescriptionAdds a new column into the table model as the last column.addListener(TableModel.Listener<V> listener) Adds a listener to this table model that will be notified whenever the model changesaddRow(Collection<V> values) Adds a new row to the table model at the end.final TableModel<V> Adds a new row to the table model at the end.clear()Removes all rows from the table, this will trigger listeners for each rowgetCell(int columnIndex, int rowIndex) Returns the cell value stored at a specific column/row coordinate.intReturns the number of columns in the modelgetColumnLabel(int index) Returns the label of a column headerReturns all column header label as a list of stringsgetRow(int index) Returns a row from the table as a list of the cell dataintReturns number of rows in the modelgetRows()Returns all rows in the model as a list of lists containing the data as elementsinsertColumn(int index, String label, V[] newColumnValues) Adds a new column into the table model at a specified index.insertRow(int index, Collection<V> values) Inserts a new row to the table model at a particular index.removeColumn(int index) Removes a column from the table modelremoveListener(TableModel.Listener<V> listener) Removes a listener from this model so that it will no longer receive any notifications when the model changesremoveRow(int index) Removes a row at a particular index from the table model.Updates the call value stored at a specific column/row coordinate.setColumnLabel(int index, String newLabel) Updates the label of a column header
-
Field Details
-
columns
-
rows
-
listeners
-
-
Constructor Details
-
TableModel
Default constructor, creates a new model with same number of columns as labels supplied- Parameters:
columnLabels- Labels for the column headers
-
-
Method Details
-
getColumnCount
public int getColumnCount()Returns the number of columns in the model- Returns:
- Number of columns in the model
-
getRowCount
public int getRowCount()Returns number of rows in the model- Returns:
- Number of rows in the model
-
getRows
-
getColumnLabels
-
getRow
-
addRow
Adds a new row to the table model at the end. This may update the selection to make sure the same row is selected.- Parameters:
values- Data to associate with the new row, mapped column by column in order- Returns:
- Itself
-
addRow
Adds a new row to the table model at the end. This may update the selection to make sure the same row is selected.- Parameters:
values- Data to associate with the new row, mapped column by column in order- Returns:
- Itself
-
insertRow
Inserts a new row to the table model at a particular index. This may update the selection to make sure the same row is selected.- Parameters:
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 order- Returns:
- Itself
-
removeRow
Removes a row at a particular index from the table model. This may update the selection to make sure the same row is selected.- Parameters:
index- Index of the row to remove- Returns:
- Itself
-
clear
Removes all rows from the table, this will trigger listeners for each row- Returns:
- Itself
-
getColumnLabel
Returns the label of a column header- Parameters:
index- Index of the column to retrieve the header label for- Returns:
- Label of the column selected
-
setColumnLabel
Updates the label of a column header- Parameters:
index- Index of the column to update the header label fornewLabel- New label to assign to the column header- Returns:
- Itself
-
addColumn
Adds a new column into the table model as the last column. You can optionally supply values for the existing rows through thenewColumnValues.- Parameters:
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...- Returns:
- Itself
-
insertColumn
Adds a new column into the table model at a specified index. You can optionally supply values for the existing rows through thenewColumnValues.- Parameters:
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...- Returns:
- Itself
-
removeColumn
Removes a column from the table model- Parameters:
index- Index of the column to remove- Returns:
- Itself
-
getCell
Returns the cell value stored at a specific column/row coordinate.- Parameters:
columnIndex- Column index of the cellrowIndex- Row index of the cell- Returns:
- The data value stored in this cell
-
setCell
Updates the call value stored at a specific column/row coordinate.- Parameters:
columnIndex- Column index of the cellrowIndex- Row index of the cellvalue- New value to assign to the cell- Returns:
- Itself
-
addListener
Adds a listener to this table model that will be notified whenever the model changes- Parameters:
listener-TableModel.Listenerto register with this model- Returns:
- Itself
-
removeListener
Removes a listener from this model so that it will no longer receive any notifications when the model changes- Parameters:
listener-TableModel.Listenerto deregister from this model- Returns:
- Itself
-