T
- The type of object representing one row in the tablepublic final class SimpleTableModel<T> extends javax.swing.table.AbstractTableModel implements ReorderableTableModel
A TableModel for displaying java.util.Lists or arrays of data in a table where each row corresponds to an element in the collection.
Columns in the table are determined by a SimpleTableFormat object which maps each column to one aspect of the row object
The change the rows of the table retrieve a java.util.List from the asList() method and manipulate it like a normal list. Changes to the list will be reflected in the table.
Constructor and Description |
---|
SimpleTableModel(java.util.List<T> tableRows)
Construct a model using row data only.
|
SimpleTableModel(java.util.List<T> tableRows,
SimpleTableFormat<T> format) |
SimpleTableModel(SimpleTableFormat<T> format) |
SimpleTableModel(T[] tableRows,
SimpleTableFormat<T> format) |
Modifier and Type | Method and Description |
---|---|
java.util.List<T> |
asList()
Returns a
List implementation that is bound to this
table model. |
java.lang.Class<?> |
getColumnClass(int columnIndex) |
int |
getColumnCount() |
java.lang.String |
getColumnName(int columnIndex) |
T |
getRow(int i)
Get an element representing a row in the table by its index.
|
int |
getRowCount() |
java.lang.Object |
getValueAt(int rowIndex,
int columnIndex) |
int |
indexOf(T element)
Return the index of the given element
|
boolean |
isCellEditable(int rowIndex,
int columnIndex) |
void |
moveRow(int start,
int end,
int to)
Moves one or more rows from the inclusive range
start to
end to the to position in the model. |
void |
rowDataChanged(int index)
The contents of a row have changed, update the ui to reflect the new values.
|
void |
rowDataChanged(T row)
The contents of a row have changed, update the ui to reflect the new values.
|
void |
setFormat(SimpleTableFormat<T> format) |
void |
setValueAt(java.lang.Object aValue,
int rowIndex,
int columnIndex) |
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
public SimpleTableModel(SimpleTableFormat<T> format)
public SimpleTableModel(java.util.List<T> tableRows)
tableRows
- public SimpleTableModel(java.util.List<T> tableRows, SimpleTableFormat<T> format)
public SimpleTableModel(T[] tableRows, SimpleTableFormat<T> format)
public java.util.List<T> asList()
List
implementation that is bound to this
table model.The binding behavior means that you can safely call methods on the returned List that make changes to the list, and they will be reflected in the model, firing appropriate events.
public int getRowCount()
getRowCount
in interface javax.swing.table.TableModel
public int getColumnCount()
getColumnCount
in interface javax.swing.table.TableModel
public java.lang.String getColumnName(int columnIndex)
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.AbstractTableModel
public java.lang.Class<?> getColumnClass(int columnIndex)
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.AbstractTableModel
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface javax.swing.table.TableModel
public void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.AbstractTableModel
public void setFormat(SimpleTableFormat<T> format)
public T getRow(int i)
i
- the index of an row in the model. Must be >= 0 and
< this.getRowCount()
.java.lang.IndexOutOfBoundsException
- if the index is out of range (index
< 0 || index >= size()).public int indexOf(T element)
element
- public void rowDataChanged(int index)
public void rowDataChanged(T row)
public void moveRow(int start, int end, int to)
ReorderableTableModel
start
to
end
to the to
position in the model.
After the move, the row that was at index start
will be at index to
.
This method should also send a tableChanged
notification
message to all the listeners.
Examples of moves:1. moveRow(1,3,5); a|B|C|D|e|f|g|h|i|j|k - before a|e|f|g|h|B|C|D|i|j|k - after
2. moveRow(6,7,1); a|b|c|d|e|f|G|H|i|j|k - before a|G|H|b|c|d|e|f|i|j|k - after
moveRow
in interface ReorderableTableModel
start
- the starting row index to be movedend
- the ending row index to be movedto
- the destination of the rows to be moved