How are you holding the data for the table? Is there a chance you could pre-sort it before building the table? You can use the java.util.Collections.sort() method to sort collections.
A better way is to hold the table data in a TableModel derivation. Have a look at the javax.swing.table.TableModel and javax.swing.table.AbstractTableModel classes. Then subclass AbstractTableModel to hold your data and set this on the JTbale using the setModel method. If you then add a sort() method to your table model which sorts the underlying data it holds, then calls the fireTableDataChanged() method of the super class, then calls to this sort method will magically sort the whole table.
You can add your own add/remove methods to your table model which allow you to add/remove rows from the underlying data which reflects in the visible JTable automatically.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.