Initiale Sortierung einer JTable

ergin

Grünschnabel
Hi,

wie kann man nach einer Spalte in einer JTable sortieren nach dem man das Datenmodel zugewiesen hat ohne dabei auf eine Spalten Überschrift zu klicken?

Mein gekürzter Code sieht wie folgt aus:

Code:
TableRowSorter rowSorter = new TableRowSorter();
JTable table = new JTable();
DefaultTableModel model = new DefaultTableModel();
table.setModel(model);
table.setRowSorter(rowSorter);
rowSorter.setModel(model);

Danke im voraus.
 
Java:
 rowSorter.toggleSortOrder(<columnIndex>);

Reverses the sort order of the specified column. It is up to subclasses to provide the exact behavior when invoked. Typically this will reverse the sort order from ascending to descending (or descending to ascending) if the specified column is already the primary sorted column; otherwise, makes the specified column the primary sorted column, with an ascending sort order. If the specified column is not sortable, this method has no effect.

Auszug aus dem Javadoc: RowSorter

Gruß

Matt
 
Zurück