Results 1 to 7 of 7
- 11-03-2009, 11:38 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 23
- Rep Power
- 0
- 11-04-2009, 02:34 AM #2
When the button is pressed then simply sort the data that is contained in that table and put it back in the table model.
My Hobby Project: LegacyClone
- 11-04-2009, 02:36 AM #3
How about if you implement your own custom TableModel (extend the stanard one) ? such as when the JTable was loaded, set it's tableModel to your own one, and have a reference to the table model visible to the button's action handler. Where in the custom table model you would have the reorder the data according to the new sort rule.
- 11-04-2009, 04:12 AM #4
Member
- Join Date
- Nov 2009
- Posts
- 23
- Rep Power
- 0
Thanks i might be able to implement that. After i sort the data and put it back do i have to "update" the table that is displayed? how do i put the data "back" and how do i "update" if i have to?
Thank you!
How about if you implement your own custom TableModel (extend the stanard one) ? such as when the JTable was loaded, set it's tableModel to your own one, and have a reference to the table model visible to the button's action handler. Where in the custom table model you would have the reorder the data according to the new sort rule.
If the above does not work ill try that, good thinking!!
-
I don't think that this is an either/or situation. You should sort your data as suggested by mrmatt and create your own table model to hold this data as suggested by pharaoh travishein. Often the best class to extend here is the DefaultTableModel class. Best of luck.
- 11-04-2009, 04:24 AM #6
Member
- Join Date
- Nov 2009
- Posts
- 23
- Rep Power
- 0
- 11-04-2009, 05:26 AM #7
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Not sure I understand the requirement. Once they click the button to sort the data, how do they unsort the data?I would like them to click a sort button.
You can use the following, but the user can still click on the header to sort as well.I cant seem to find a fireSort type of method in TableRowSorter.
I know you can disable sorting on specific columns. I don't know if that applies to just clicking on the header or by sorting manually as well.Java Code:table.setAutoCreateRowSorter(true); DefaultRowSorter sorter = ((DefaultRowSorter)table.getRowSorter()); ArrayList list = new ArrayList(); list.add( new RowSorter.SortKey(0, SortOrder.ASCENDING) ); sorter.setSortKeys(list); sorter.sort();
Similar Threads
-
How to span column headers over several columns
By thayalan in forum AWT / SwingReplies: 0Last Post: 06-02-2009, 04:33 PM -
JCheckBox in JTable column
By hind in forum New To JavaReplies: 8Last Post: 01-04-2009, 07:40 PM -
tooltips for JTable column headers
By fossildoc in forum AWT / SwingReplies: 2Last Post: 12-18-2008, 11:42 AM -
Sorting a SWT table by column
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 03:07 PM -
How to sort column in JTable
By johnt in forum AWT / SwingReplies: 3Last Post: 06-14-2008, 05:48 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks