• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sorting on other columns (and related question)

 
Ranch Hand
Posts: 89
Netscape MySQL Database Windows XP
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 89
    Netscape MySQL Database Windows XP
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Rancher
    Posts: 3324
    32
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 89
    Netscape MySQL Database Windows XP
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rob Camick wrote:Make each column unsortable



    Yep. thanks.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic