Is there a way where I can have a parent JTable sort value be passed and set the sort of a child JTable in Java 1.4? What I have is a parent JTable of subjects with about 6 columns and a child JTable that is a subset of the parent JTable with the same columns. What I need to do is when the user selects a item from the parent JTable and updates the child JTable, the sort is changed to whatever the parent JTable is at that time. I had this working fine with Java 1.6 with the TableRowSorter class until I realized I had to use Java 1.4 - which the TableRowSorter class is non-existent.
+1
A:
Is the problem that you need to provide a sort for your tables the way that TableRowSorter
did, or that you need to pass the sort key from the parent to the child?
If the former, you could back your JTables
with a TableModel
s that contain row objects that implement Comparable
. You can then implement your own Comparator
classes per column. You can then, in your custom TableModel
set the appropriate Comparator
on your backing sorted Collection.
If the latter, I imagine that you are implementing ListSelectionListener
in order to trigger the population of the child table with the correct data. In this same process you can query the parent table for its current Comparator
and apply that to the child table model.
akf
2010-02-16 02:36:47
The problem is that I need to provide a way to sort the way that TableRowSorter did. I do have a custom TableModel, but I'm not sure how to tie that back to the child table.
anseltim
2010-02-16 03:26:18
Thanks for pointing me in the right direction. I got it working now with using the coumn index from the parent table to set the sort on the child table.
anseltim
2010-02-16 17:32:52