Results 1 to 7 of 7
- 04-24-2011, 12:26 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
Auto sorting JTable by second column
Hello all
I am building a program that displays files and folders from a specific folder on my drive using a JTable component. I have created a custom renderer to show jlabel components with images and it's all working great. I also created a custom comparator class that does exactly what i want when i press on the table header. The issue is that i cannot find how to simulate a user clicking on the second column. It always defaults to the first one and i've been searching for days for a solution. Here's one i found on the oracle page and even that doesn't work :
TableRowSorter sorter = new TableRowSorter(getModel());
Comparator comp = new FolderTableSorter(false);
sorter.setComparator(0, comp);
sorter.setComparator(1, comp);
sorter.setComparator(2, comp);
List<RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
sortKeys.add(new RowSorter.SortKey(1, SortOrder.DESCENDING));
sorter.setSortKeys(sortKeys);
sorter.toggleSortOrder(1);
setRowSorter(sorter);
((FolderTableModel)getModel()).fireTableDataChange d();
revalidate();
As you can see i tried all sorts of methods that i thought MIGHT update the table lol. The odd thing is calling togglesortorder actually puts a little triangle in the column header but it doesn't update the table. By the way, this is all hapenning in a JTable subclass with internal nested classes for the renderer and what not.
Any help would be appreciated!
Martin
- 04-25-2011, 12:12 AM #2
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
bump, Anyone?
- 04-25-2011, 01:22 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Posting a SSCCE might help. If the problem is with the sorting a small table with strings should be enough.
- 04-25-2011, 04:14 AM #4
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
I need a custom renderer to display comboboxes, images, buttons and all kinds of stuff in the cells. I'm doing something on the scale of explorer basically.
- 05-01-2011, 06:38 PM #5
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
I'm not sure what more you want besides this code example. The table sorting is working perfectly fine except it sorts it by default by the first column and i want it to sort the second column by default. Manually pressing the column header works great. I would just like to simlulate someone pressing the second table header upon startup.
- 05-06-2011, 01:13 AM #6
Member
- Join Date
- Apr 2011
- Posts
- 69
- Rep Power
- 0
So nobody knows how to simulate clicking on the second column header without clicking on it?
-
Similar Threads
-
JTable: Disable sorting on one column
By b.newworld@gmail.com in forum AWT / SwingReplies: 1Last Post: 09-16-2010, 12:43 AM -
JTable column header sorting direction arrows and row selection on focus loss
By r00tb33r in forum AWT / SwingReplies: 1Last Post: 07-28-2010, 03:46 PM -
Sorting in JTable without clicking on column headers
By ProgrammingPup in forum Advanced JavaReplies: 6Last Post: 11-04-2009, 05:26 AM -
Auto updation of Editable Column Indexes
By Gajesh Tripathi in forum AWT / SwingReplies: 0Last Post: 10-23-2008, 10:23 AM -
Sorting a SWT table by column
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 03:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks