• Post Reply Bookmark Topic Watch Topic
  • New Topic

disable sorting by clicking on the JTable headers

 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to disable sorting by clicking on the JTable headers?

I have tried a few ways but because I am sorting the data when I load it that 'breaks' that also. Here is what I am trying to achieve.

Sort by 3 columns:

table.setAutoCreateRowSorter(true);

table.getRowSorter().toggleSortOrder(6);

table.getRowSorter().toggleSortOrder(7);

table.getRowSorter().toggleSortOrder(5);
table.getRowSorter().toggleSortOrder(5);


but then I want it so the user cannot resort that when the table is displayed...

Thanks in advance!
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried creating a sub class of TableRowSorter and overriding isSortable to return false?
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had not tried that, but I just did and that works for the user not being able to sort after the table is displayed, but it also disregards the sorting I am doing in the code. I need to have things in the sorted order but the user to not be able to change it...
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should work for you (along with default row sorter):
 
Stephanie Challand
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That did it! Thank You!!
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
table.getTableHeader().setEnabled(false);

is wrong then how do you, e.g. reorder column and another a few another important mouse & key events (there are KeyBindings too)

_______________________________________________________________________________________


sorter.setSortable(0, false);

or to override

setAutoCreateRowSorter (false)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!