final class TableSortIndicator extends Observable
This class does not do any sorting of the underlying rows - it merely indicates the identity and direction of the sorted column.
The user changes the indicated sort by simply clicking on a column header. The initial click always indicates a descending sort. A re-click on the same column will toggle the indicated direction.
Listeners to this class are notified when the sort has changed, and
use getSortBy()
to retrieve the new sort, and then perform the actual
sorting. Example :
TableSortIndicator fSortIndicator = new TableSortIndicator(table, upIcon, downIcon); fSortIndicator.addObserver(this); //when the user clicks a column header, fSortIndicator will notify //registered observers, who will call getSortBy to fetch the new sort. //.. public void update(Observable aObservable, Object aData) { //extract column and (asc|desc) from fSortIndicator SortBy sortBy = fSortIndicator.getSortBy(); //...perform the actual sorting }Instead of using a mouse click, the sort can be set programmatically as well; this is useful for reflecting a sort selected through a preferences dialog. Example :
TableSortIndicator fSortIndicator = new TableSortIndicator(table, upIcon, downIcon); fSortIndicator.addObserver(this); fSortIndicator.setSortBy(sortByPreference) ; //setSortBy calls the update method
Constructor and Description |
---|
TableSortIndicator(JTable aTable,
Icon aUpIcon,
Icon aDownIcon)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) SortBy |
getSortBy()
Return the identity of column having the primary sort, and the direction
of its sort.
|
(package private) void |
setSortBy(SortBy aTargetSort)
Change the sort programmatically, instead of through a user click.
|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
TableSortIndicator(JTable aTable, Icon aUpIcon, Icon aDownIcon)
aTable
- receives indication of table sort ; if it has any custom
header renderers, they will be overwritten by this class.aUpIcon
- placed in column header to indicate ascending sort.aDownIcon
- placed in column header to indicate descending sort.Copyright Hirondelle Systems - License - Generated 2013Sep20.10.58