This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable set up default auto-sorted column  RSS feed

 
Alexander Pupkin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear community,

let me ask you a question: how can I defined column to be auto-sorted?
The problem is the following: creating JTable with some columns, set auto sort to true and some other cosmetic stuff.

I'm perfectly happy with the result on the screen with the only exception - each time this window appear I need to click on the first column to make logs display sorted by they appearance - how can I make JTable window appear with the column #0 sorted by default, with no writing my personal sorter?

Googled, but didn't find any tricks on this.

Thanks in advance,
Regards,
/Alexander.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> how can I make JTable window appear with the column #0 sorted by default

table.getRowSorter().toggleSortOrder(0);
 
Alexander Pupkin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
> how can I make JTable window appear with the column #0 sorted by default

table.getRowSorter().toggleSortOrder(0);


As easy and great as expected - thanks a lot!

Last sub-question: how can I reverse order for this column? Didn't find right method at the RowSorter instance...
 
Alexander Pupkin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last sub-question: how can I reverse order for this column? Didn't find right method at the RowSorter instance...[/QB]


My apologize - it's the same method call =)

Thanks a lot!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!