public class SortedTableModel
extends javax.swing.table.AbstractTableModel
implements javax.swing.event.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(javax.swing.table.TableModel model)
initializes with the given model
|
Modifier and Type | Method and Description |
---|---|
void |
addMouseListenerToHeader(javax.swing.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.
|
java.lang.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
|
java.lang.String |
getColumnName(int columnIndex)
Returns the name of the column at columnIndex
|
javax.swing.table.TableModel |
getModel()
returns the current model, can be null
|
int |
getRowCount()
Returns the number of rows in the model.
|
java.lang.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(javax.swing.table.TableModel value)
sets the model to use
|
void |
setValueAt(java.lang.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(javax.swing.event.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(javax.swing.table.TableModel model)
model
- the model to initialize the sorted model withpublic void setModel(javax.swing.table.TableModel value)
value
- the model to usepublic javax.swing.table.TableModel getModel()
public boolean isSorted()
public int getActualRow(int visibleRow)
visibleRow
- the displayed row to retrieve the original row forpublic java.lang.Class<?> getColumnClass(int columnIndex)
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
columnIndex
- the index of the columnpublic 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
columnIndex
- the column to retrieve the name forpublic int getRowCount()
getRowCount
in interface javax.swing.table.TableModel
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
getValueAt
in interface javax.swing.table.TableModel
rowIndex
- the rowcolumnIndex
- the columnpublic boolean isCellEditable(int rowIndex, int columnIndex)
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.AbstractTableModel
rowIndex
- the rowcolumnIndex
- the columnpublic void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.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(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
e
- the eventpublic void addMouseListenerToHeader(javax.swing.JTable table)
table
- the table to add the listener to