TableSorter slow?

Hello

Let me begin by saying I am a novice, and I appreciate very much SUN's extra effort in making classes like TableSort publicy available. However, I have a JTable that use TableSort, and I find it very slow in sorting. Since I do not understand all code (in partucular those regarding listeners) in TableSort, I am unsure whether it is my implementation of TableModel that is causing this, or TableSort itself.

My JTable is moderately large: it has ~400 000 lines. The program paints the JTable quckly enough, but sorting a column takes a long while (I loose patience after 10 min..).

My TableModel is infact a TreeModel that implements TableModel, and as such I suspect the getValueAt() methods may not be super-efficient. However, do you believe the slow sort is a result of such a TableModel? Or do you believe it is simply too much data to sort effective?

I have an idea for increasing sort speed. My table is not editable (no inserts or deletion or celledits allowed), so any sorting would only constitute in a reverse order of the view index (or is it model index?), alternative using original index. But, alas I am not capable enough to make these changes in the TableSort code.

I know that sorting an Array of data is much much faster.

Your experience or comment is appreciated.

Regard

Fluid

[1362 byte] By [Fluida] at [2007-10-2 4:00:29]
# 1

Using self-made TableModels is extremely simple.

Only the triggering of events need to be done carefully.

In your case a self-made TableModel that sorts an basic TableModel would be easily made.

The TableSorter I know of, contained its own sorting algorithm.

For your case I would consider the sort in java.util.Collections or Arrays.

Another improvement would be to require that your objects implement the Comparable interface should they that column be sortable.

If you can use a second array, you can detach the sorting in the background.

Furthermore getValueAt should be fast.

joop_eggena at 2007-7-15 23:22:34 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks for encourage me to implement this myself. Now the sorting is much much faster, and I also implemented a context-menu for sorting.RegardsFluid
Fluida at 2007-7-15 23:22:34 > top of Java-index,Desktop,Core GUI APIs...