• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable setAutoCreateRowSorter method and getting key from maps  RSS feed

 
K. Tsang
Bartender
Posts: 3633
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I use a table model to create a table with setAutoCreateRowSorter(true) and click the column. When I do table.getSelectedRow() will return that particular row number. Now if I use this number to call my Data's read method, it doesn't fetch the corresponding record. I have stored the data set in a hash map, yet the key (record number) are static or fixed.

Is there a method for a map to get its key given the value? Like instead of getting the value from get(Object key), i want get(Object value) to return the key. So that I can pass the key (record number) to my Data read method.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To support build in table sorters, the table has new methods to help you with this problem.
Check out JTable#convertRowIndexToModel(int viewRowIndex)

Swing related.
Moving.
 
K. Tsang
Bartender
Posts: 3633
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow you are great. Thanks.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hahaha!
I am sure I am nothing of that sort.
It's just that I had encountered the same problem earlier and that's how I knew the answer. And now so do you
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!