|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmckay.utilities.gui.tables.TableSortModel
public class TableSortModel
This class serves as an intermediate TableModel that can be used to implement sorting of JTables with DefaultTableModel TableModels.
The setColumnWidths method also allows JTables to have the width of some of their columns automatically set in order to fit the contents of the columns.
Constructor Summary | |
---|---|
TableSortModel(javax.swing.JTable table)
Attaches a MouseListener to the column headings of the given JTable so that it will be sorted based on the contents of that column whenever the column heading is pressed. |
Method Summary | |
---|---|
void |
addRow(java.lang.Object[] row_data)
Adds a row to the end of the TableModel. |
void |
addTableModelListener(javax.swing.event.TableModelListener listener)
Adds the given listener to the table model. |
java.lang.Class |
getColumnClass(int column)
Returns the class of the column at the given index. |
int |
getColumnCount()
Returns the number of columns in the table. |
java.lang.String |
getColumnName(int column)
Returns the name of the column at the given index. |
int |
getRowCount()
Returns the number of rows in the table. |
int |
getTrueRowIndex(int row)
Returns the row index of the true table model that corresponds to the row index in the sorted table model. |
java.lang.Object |
getValueAt(int row,
int column)
Returns the corresponding contents of the real TableModel. |
boolean |
isCellEditable(int row,
int column)
Returns the whether the given cell is editable or not. |
void |
removeRows(int[] row_indexes)
Removes the rows with the given indexes from the TableModel. |
void |
removeTableModelListener(javax.swing.event.TableModelListener listener)
Removes the given listener to the table model. |
static void |
setColumnWidths(javax.swing.JTable table,
javax.swing.table.TableColumn[] columns_to_set,
int max)
Resets the column widths of the given JTable so that each of the given columns has enough space to fit its header and all of its contents in the column, and no more. |
void |
setValueAt(java.lang.Object value,
int row,
int column)
Sets the corresponding contents of the real TableModel. |
void |
tableChanged(javax.swing.event.TableModelEvent event)
This method currently does nothing. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TableSortModel(javax.swing.JTable table) throws java.lang.IllegalArgumentException
table
- The table that this object is to serve as an
intermediateTableModel for. This may not have a null
TableModel when it is passed here, and its TableModel
must be a DefaultTableModel.
java.lang.IllegalArgumentException
- Throws an informative exception
if a null argument is passed.Method Detail |
---|
public void tableChanged(javax.swing.event.TableModelEvent event)
tableChanged
in interface javax.swing.event.TableModelListener
event
- Any TableModelEvent that could trigger some action.public static void setColumnWidths(javax.swing.JTable table, javax.swing.table.TableColumn[] columns_to_set, int max)
table
- The table whose column widths are to be changed.columns_to_set
- The columns to be resized. These must all be
in the given table.max
- The rough maximum width of each of the given
columns, in characters.public int getTrueRowIndex(int row)
row
- The row index of the TableSortModel to query.
public void addRow(java.lang.Object[] row_data)
row_data
- The row to add to the TableModel.public void removeRows(int[] row_indexes)
row_indexes
- The indexes of the rows to delete.public java.lang.Object getValueAt(int row, int column)
getValueAt
in interface javax.swing.table.TableModel
row
- The index of the sorted table.column
- The index of the column.
public void setValueAt(java.lang.Object value, int row, int column)
setValueAt
in interface javax.swing.table.TableModel
value
- The entry to place in the table.row
- The index of the sorted table.column
- The index of the column.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 column)
getColumnName
in interface javax.swing.table.TableModel
column
- The index of the column.
public java.lang.Class getColumnClass(int column)
getColumnClass
in interface javax.swing.table.TableModel
column
- The index of the column.
public boolean isCellEditable(int row, int column)
isCellEditable
in interface javax.swing.table.TableModel
row
- The index of the sorted table.column
- The index of the column.
public void addTableModelListener(javax.swing.event.TableModelListener listener)
addTableModelListener
in interface javax.swing.table.TableModel
listener
- The listener to add.public void removeTableModelListener(javax.swing.event.TableModelListener listener)
removeTableModelListener
in interface javax.swing.table.TableModel
listener
- The listener to remove from the table model.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |