Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a DefaultTableModel

Status
Not open for further replies.

Handle6

Programmer
Jan 28, 2005
4
DE
Hi,

how can I sort a DefaultTableModel?

I've only found things with JTable, but I only wan't to sort my TableModel and don't use the JTable for viewing it (no output on the screen).
 
You could always roll-your-own by table model with sorting capabality by subclassing AbstractTableModel, or maybe add a sort method to DefaultTableModel by subclassing that.
 
Let me be more precise:

are there any standart-implementations for sorting a TableModel?
 
Have you tried the Collections.sort(..) methods? Maybe something like the following would work?

Code:
MyComparator comparator = new MyComparator....
Collections.sort(tableModel.getDataVector(), comparator);
tableModel.fireTableDataChanged();

Tim
 
Yes, I tried it yet.
No, did not work ,(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top