public class SortedTableModel
extends java.lang.Object
implements javax.swing.table.TableModel
SortedTableModel
can be used to provide row
sorting services for any
javax.swing.table.TableModel
. The new model
simply wraps the old one and translates row indicies through
the wrapper so as to make it appear that the table is sorted
according to the values held in a specific column of the
table.Constructor and Description |
---|
SortedTableModel(javax.swing.table.TableModel model)
Creates a sorted model using the specified unsorted model
for its data.
|
Modifier and Type | Method and Description |
---|---|
void |
addTableModelListener(javax.swing.event.TableModelListener l) |
int |
convertRowIndexToModel(int row)
Converts a row index in the sorted model to a row index in the
underlying model.
|
int |
convertRowIndexToView(int row)
Converts a row index in the underlying model to a row index in the
sorted model.
|
java.lang.Class |
getColumnClass(int columnIndex) |
int |
getColumnCount() |
java.lang.String |
getColumnName(int columnIndex) |
boolean |
getIsAscending()
Gets the current sorting order.
|
int |
getRowCount() |
int |
getSortColumn()
Gets the current sorting column, or -1 for no sorting.
|
java.lang.Object |
getValueAt(int rowIndex,
int columnIndex) |
boolean |
isCellEditable(int rowIndex,
int columnIndex) |
void |
removeTableModelListener(javax.swing.event.TableModelListener l) |
void |
setSort(int sortColumn,
boolean isAscending)
Set the sorting column and order.
|
void |
setValueAt(java.lang.Object aValue,
int rowIndex,
int columnIndex) |
public SortedTableModel(javax.swing.table.TableModel model)
model
- the model to use for row and column data.public void setSort(int sortColumn, boolean isAscending)
sortColumn
- the new sorting column, or -1 for no sorting.isAscending
- the new sorting order, true for
ascending.public int getSortColumn()
public boolean getIsAscending()
public int convertRowIndexToModel(int row)
row
- the row index to convert.public int convertRowIndexToView(int row)
row
- the row index to convert.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
public java.lang.Class getColumnClass(int columnIndex)
getColumnClass
in interface javax.swing.table.TableModel
public boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface javax.swing.table.TableModel
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
public void addTableModelListener(javax.swing.event.TableModelListener l)
addTableModelListener
in interface javax.swing.table.TableModel
public void removeTableModelListener(javax.swing.event.TableModelListener l)
removeTableModelListener
in interface javax.swing.table.TableModel