Skip to main content

Strange sort problem with JXTable

5 replies [Last post]
roger_gl
Offline
Joined: 2009-02-15

Hi,
I just switched my whole application from using JTable to using JXTable. Most things work as expected but one area fails completely. I have some tables that uses a table model (see http://www.javaworld.com/javaworld/javatips/jw-javatip137.html?page=2 for details) that fetches data on demand from the database.. When I use a Java 6 TableRowSorter and a JTable I get exactly 1 call to the database to fetch the data the table needs to display after clicking on the header to sort the table. If I use JXTable I get A LOT of calls. It seems that before resorting the table all data is fetched. An with a large dataset this can take minutes to complete Any ideas how to improve this ?

Regards
Roger

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08

Roger,

What calls are forcing the update from the database? Can you provide a stacktrace for them?

Karl

roger_gl
Offline
Joined: 2009-02-15

Hi Karl,

the database calls are all triggered from the getValueAt call:

public Object getValueAt(int rowIndex, int columnIndex) {
return tableClientCache.retrieveRowFromCache(rowIndex)[columnIndex];
}

Can you provide a stacktrace for them?
-------------------------------------------------------------
I have only a vague idea how to do that. Maybe force a heap dump after the third call to retrieveRowFromCache ?

Regards
Roger

kschaefe
Offline
Joined: 2006-06-08

Just add the following as the first line of getValueAt:
new Exception().printStackTrace();

Run once for JTable and once for JXTable. Let's see what's causing the requerying of getValueAt in JXTable that is not occuring in JTable.

Karl

roger_gl
Offline
Joined: 2009-02-15

Thanks for the tip with new Exception().printStackTrace(). It showed that JXTable used a rowsorter. After setting the row sorter to null I JXTable now behaves exactly as JTable.

Regards
Roger

kschaefe
Offline
Joined: 2006-06-08

Yes, JXTable has a row sorter by default. This is opposite of how core works.

Karl