Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting the rows in a JTable  RSS feed

 
srinivas murthy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai friends,
I want the code for sorting entire records in a Jtable.i know how to sort a perticular column.But i need to sort entire records in a JTAble.If any one knows the solution please help me..Waiting for a reply...
Regards,
Srinivas.
 
Deepal Mehta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check for the edited rows & whenever you encounter an unedited row or a blank row, stop incrementing the counter. For that use getRowCount() method within the for loop.
i.e for(i-0;i<=TableName.getRowCount();i++){

write the code here to find the unedited row
}
 
Edward Liu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
Check out the "How to Use Tables" tutorial in the main Java Tutorial (you can find it by going to the Java documentation and then to JTable -- the link should be up near the top). Specifically, there's a whole section down near the bottom which deals with TableModels and how to use them. It also comes with code that you can steal wholesale and use, if you don't care about how it works. The basic idea is that you stick an intermediary table model between the table and your real table model. The intermediary provides a mapping between the real table data and the order it is to be displayed on the screen. Thus, to sort the table, you just reorder the mapping rather than move around data in the underlying table model.
I'm not explaining this terribly well, but the tutorial is pretty good at explaining what it's doing.
-- Ed
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!