File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Setting the data in a JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting the data in a JTable" Watch "Setting the data in a JTable" New topic
Author

Setting the data in a JTable

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I have a table, that allows users to sort the data. They can also select any of the rows in the JTable, and it throws the information into text fields, so they can modify the data. Once they hit save, the data in the table is refreshed. My problem I am running into, is if the user has sorted the table into the order they want it, then hit save, the data in the JTable is set back to its original order.
How can I refresh the data of the JTable when it changes, without reordering the rows?

Below is how I am setting the data of the table:



And I am using Sun's TableSorter class to sort the columns
Here is a link to that class:
TableSorter

Thanks for any help!!
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I think I found a workaround. I added a variable to TableSorter that holds the index of the last column sorted on. Whenever I refresh the data in the table, I run the sortByColumn() method on the TableSorter class using the
index of the last column that was sorted on.

If anyone has a better solution, please let me know!

Thanks!
 
 
subject: Setting the data in a JTable