Sorted JTable
[Previous] [Main] [Next]

Sorted JTable


If you click on the column header for any column in the JTable the table will redisplay sorted on that column. Click on the header again and it will sort in the other direction.

There is a special class that does this (TableModelSorter.java), and this works great if you are using tables based on arrays (See the SQLWhereClause.java file for an example.) On the other hand I have converted JGuiGen to use the resultset generated by querying the SQL backend directly. This method elmininates a lot of walking through the entire resultSet and converting it to an array.

I found that even a thousand rows in the table sometimes ( particlarly with SQL-SERVER ) lead to unacceptable wait times. Now JGuiGen queries the SQL backend again and appends an "ORDER BY" to the query.