public class SortedTableModel extends AbstractTableModel implements TableModelListener
Modifier and Type | Class and Description |
---|---|
static class |
SortedTableModel.SortContainer
Helper class for sorting the columns.
|
Constructor and Description |
---|
SortedTableModel()
initializes with no model
|
SortedTableModel(TableModel model)
initializes with the given model
|
Modifier and Type | Method and Description |
---|---|
void |
addMouseListenerToHeader(JTable table)
Adds a mouselistener to the header: left-click on the header sorts in
ascending manner, using shift-left-click in descending manner.
|
int |
getActualRow(int visibleRow)
Returns the actual underlying row the given visible one represents.
|
Class |
getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the
column.
|
int |
getColumnCount()
Returns the number of columns in the model
|
String |
getColumnName(int columnIndex)
Returns the name of the column at columnIndex
|
TableModel |
getModel()
returns the current model, can be null
|
int |
getRowCount()
Returns the number of rows in the model.
|
Object |
getValueAt(int rowIndex,
int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.
|
boolean |
isCellEditable(int rowIndex,
int columnIndex)
Returns true if the cell at rowIndex and columnIndex is editable.
|
boolean |
isSorted()
returns whether the table was sorted
|
void |
setModel(TableModel value)
sets the model to use
|
void |
setValueAt(Object aValue,
int rowIndex,
int columnIndex)
Sets the value in the cell at columnIndex and rowIndex to aValue.
|
void |
sort(int columnIndex)
sorts the table over the given column (ascending)
|
void |
sort(int columnIndex,
boolean ascending)
sorts the table over the given column, either ascending or descending
|
void |
tableChanged(TableModelEvent e)
This fine grain notification tells listeners the exact range of cells,
rows, or columns that changed.
|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
public SortedTableModel()
public SortedTableModel(TableModel model)
model
- the model to initialize the sorted model withpublic void setModel(TableModel value)
value
- the model to usepublic TableModel getModel()
public boolean isSorted()
public int getActualRow(int visibleRow)
visibleRow
- the displayed row to retrieve the original row forpublic Class getColumnClass(int columnIndex)
getColumnClass
in interface TableModel
getColumnClass
in class AbstractTableModel
columnIndex
- the index of the columnpublic int getColumnCount()
getColumnCount
in interface TableModel
public String getColumnName(int columnIndex)
getColumnName
in interface TableModel
getColumnName
in class AbstractTableModel
columnIndex
- the column to retrieve the name forpublic int getRowCount()
getRowCount
in interface TableModel
public Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface TableModel
rowIndex
- the rowcolumnIndex
- the columnpublic boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface TableModel
isCellEditable
in class AbstractTableModel
rowIndex
- the rowcolumnIndex
- the columnpublic void setValueAt(Object aValue, int rowIndex, int columnIndex)
setValueAt
in interface TableModel
setValueAt
in class AbstractTableModel
aValue
- the new value of the cellrowIndex
- the rowcolumnIndex
- the columnpublic void sort(int columnIndex)
columnIndex
- the column to sort overpublic void sort(int columnIndex, boolean ascending)
columnIndex
- the column to sort overascending
- ascending if true, otherwise descendingpublic void tableChanged(TableModelEvent e)
tableChanged
in interface TableModelListener
e
- the eventpublic void addMouseListenerToHeader(JTable table)
table
- the table to add the listener toCopyright © 2019 University of Waikato, Hamilton, NZ. All rights reserved.