sort column of table

Hi,

I'm using this

private JScrollPane spNotPlaying =new JScrollPane();

private DefaultTableModel dtmNotPlaying;

private JTable tNotPlaying;

spNotPlaying.getViewport().setView(tNotPlaying);

tNotPlaying =new JTable(dtmNotPlaying);

Can someone give me code which can sort column of table? I want to click on header (column name) and sort it.

Thanks.

Message was edited by:

boba5555

[616 byte] By [boba5555a] at [2007-10-3 9:43:14]
# 1
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting
PhHeina at 2007-7-15 4:59:32 > top of Java-index,Desktop,Core GUI APIs...
# 2
http://java.sun.com/docs/books/tutorial/uiswing/components/table.htmlAlso, a search in google for TableSorter and/or TableSorter.java will give you all the code and info you should need.
cimmerian76a at 2007-7-15 4:59:32 > top of Java-index,Desktop,Core GUI APIs...
# 3

Thanks.

I'm using code from this page

[url]http://java.sun.com/docs/books/tutorial/uiswing/components/examples/TableSorter.java[/url]

and setModel like this

sorter = new TableSorter(dtmNotPlaying);

tNotPlaying = new JTable(sorter);

sorter.setTableHeader(tNotPlaying.getTableHeader());

private DefaultTableModel dtmNotPlaying;

private JTable tNotPlaying;

TableSorter sorter;

When I do this

dtmNotPlaying.addRow(new Object[] {<some variables>});

I can see changes in tNotPlaying. How does dtmNotPlaying "say" to sorter (I know that sorter should "says" to tNotPlaying) that it should add new row and make it sorted or where does it "say" in code? It works, but why :)

Thanks.

boba5555a at 2007-7-15 4:59:32 > top of Java-index,Desktop,Core GUI APIs...
# 4
A TableMOdelListener is added to the TableModel. So it knows when changes are made and can redo the sort.
camickra at 2007-7-15 4:59:32 > top of Java-index,Desktop,Core GUI APIs...