I know that Jtable can sort by a single column. But is it possible to allow for multiple column sort or do i need to write the code myself?
Thanks in advance
I know that Jtable can sort by a single column. But is it possible to allow for multiple column sort or do i need to write the code myself?
Thanks in advance
You should be able to set the TableRowSorter and the Comparator associated with it. Example:
TableModel myModel = createMyTableModel();
JTable table = new JTable(myModel);
TableRowSorter t = new TableRowSorter(myModel);
t.setComparator(column that the comparator works against, Comparator<?> comparator);
table.setRowSorter(new TableRowSorter(myModel));
Look into JXTable. JXTable is an extension of JTable that supports multi-column sorting, as well as other functions that JTable doesn't provide. It's freely available from JDNC / SwingLabs.
You can sort by multiple columns by specifying more than one sort key when calling setSortKeys
in the RowSorter
you're using.