Special JTable setup: how to do sorting?

F

Felix Natter

hallo,

I have a JTable with fixed footer and header rows, implemented by using
three JTables in a vertical BoxLayout which share a common
TableColumnModel. All the data is stored in a few custom TableColumn's,
instead of in the TableModel (TableModel.getValueAt returns null). The
custom TableColumn's also implement TableCellRenderer so that they
create the cell renderer widgets (some custom, many JLabel's).

Now when I use:
middletable.setAutoCreateRowSorter(true);
I can click on the header fields, but when I do it is indicated that
*all* columns are sorted ascending/descending, and it doesn't do any
sorting (probably because the Tablemodel doesn't store any data?).

Is there another way, maybe on a lower level, to do the sorting?

Is there a way to catch mouse clicks on header cells so that I can do it
manually by keeping an index array for all TableColumn's and inserting
Unicode chars for "sorted ascending"/"sorted descending" in the header
cell? Would Component.processMouseEvent() in combination with
JTableHeader.columnAtPoint() be the right direction?

Thanks a lot in advance!
 
J

John B. Matthews

Felix Natter said:
I have a JTable with fixed footer and header rows, implemented by
using three JTables in a vertical BoxLayout which share a common
TableColumnModel. All the data is stored in a few custom
TableColumn's, instead of in the TableModel (TableModel.getValueAt
returns null). The custom TableColumn's also implement
TableCellRenderer so that they create the cell renderer widgets (some
custom, many JLabel's).

Now when I use:
middletable.setAutoCreateRowSorter(true);
I can click on the header fields, but when I do it is indicated that
*all* columns are sorted ascending/descending, and it doesn't do any
sorting (probably because the Tablemodel doesn't store any data?).

Is there another way, maybe on a lower level, to do the sorting?

Is there a way to catch mouse clicks on header cells so that I can do
it manually by keeping an index array for all TableColumn's and
inserting Unicode chars for "sorted ascending"/"sorted descending" in
the header cell? Would Component.processMouseEvent() in combination
with JTableHeader.columnAtPoint() be the right direction?

IIUC, you want clicking on the header to sort only the middle table's
rows? I think you need a proper TableModel, even if it only provides
the middle table's data. Note that the DefaultRowSorter can have a
Comparator for each column. Regarding mouse handling, you might get
some inspiration from Sun's pre-1.6 TableExample, which used Philip
Milne's TableSorter class:

<http://groovy.codehaus.org/xref/groovy/inspect/swingui/TableSorter.html>

Not all Unicode glyphs are available on all implementations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top