Reputation: 665
How to sort rows in JTable in ascending or descending order while adding new rows to JTable?
Upvotes: 0
Views: 830
Reputation: 877
Depending on your needs whether or not you need to sort on multiple columns, you can add a TableModelListener to your table model, to execute custom behaviour when the table model changes. Just implement the
public void tableChanged(TableModelEvent e)
method to capture the event and sort the required collumn. One way of doing this is to map work with an index map which refers to the data of the column you want to sort and resort the index map according to the column that you want to sort.
Upvotes: 1