• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting on other columns (and related question)  RSS feed

 
Daan Heuvelbeuk
Ranch Hand
Posts: 85
MySQL Database Netscape Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In How to Use Tables - Sorting sorting of tables is explained. In my application I'm so far as to be able to (pre) sort my table on one column. But I want to be able to sort on more columns. in 'How to Use Tables - Sorting' it is said "To specify the sort order and sort precedence for columns, invoke setSortKeys. " setSortKeys is part of the DefaultRowSorter class. What should I do to be able to use DefaultRowSorter.setSortKeys?

In the following code, from said Oracle document, I changed some parts. I changed the names of the persons in the table, to make my point clear (I added two John's). I also added a row sorter to the table, and toggled the sort order. The result is that the table is displayed sorted on the first names. But the last names are not in order. I would like to be able to add a second sorter on the last names. It would be something like:I know I need to add my own implementation of the DefaultRowSorter to my code. But what do I need to do to let my class, in this example TableSortDemo, communicate with my implemenation of the DefaultRowSorter?

My questions:
  • How do I get the DefaultRowSorter.setSortKeys in this code?
  • Is it possible to add a pre-sort to my table, and then remove the sorting capability from the table?


  • My (filched) code:
     
    Daan Heuvelbeuk
    Ranch Hand
    Posts: 85
    MySQL Database Netscape Windows XP
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I found one answer on codejava.net in the zip file JTableSortingExample.zip. In the file JTableSortingExample.java the problem is solved.

    In the above mentioned code insert on line 20add

    Now if someone can tell me if it is possible, after sorting, to prohibit sorting by the user, I would be happy.
     
    Rob Camick
    Ranch Hand
    Posts: 2787
    12
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    if it is possible, after sorting, to prohibit sorting by the user,


    Make each column unsortable:

     
    Daan Heuvelbeuk
    Ranch Hand
    Posts: 85
    MySQL Database Netscape Windows XP
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Rob Camick wrote:Make each column unsortable


    Yep. thanks.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!