0

By default, if you have more than one SortKey in a JTable's row-sorter, every click on a column header will make that column's SortKey to be the primary one.

I need to change this behaviour so the first click on a column header makes that SortKey the primary one, a click to another column header would make that column's SortKey the secondary one, and so on.

Also, when, say maxSortKeys is reached, a click on another (not sorted) column would trigger the shuffling of sort-keys. The newly clicked column would have SortKey with lowest priority, the primary key column will lose its SortKey, and the column with secondary SortKey will become the primary one, etc.

At the moment, I implemented my own TableHeader in order to capture the event when user clicks on the column header in order to shuffle SortKeys appropriately.

To illustrate it with an example:

[ One | Two ↑1 | Three ↓2 | Four | Five ↑3 ]
[     |        |          |      |         ]

After user clicks on the first column's header:

[ One ↑3 | Two  | Three ↓1 | Four | Five ↑2 ]
[        |      |          |      |         ]

What I wonder is whether you think this is a good approach or not?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
DejanLekic
  • 18,787
  • 4
  • 46
  • 77

1 Answers1

1
  • is required to override SortKeys for every columns, for each of columns should be own arrays of SortKeys (sure if required)

  • there is reasonble to use max 6-8 SortKeys in visible rectangle returns by JViewport, otheriwse I can see performance issue and ghosts inside JScrollPane from repainting

  • SortOrder.UNSORTED isn't initial sort order, JTables view can't store, remember that, don't know proper way, only to refresh JTable from its model

  • for example

  • you can to show sort Icon programatically

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • Answer to your first question - not necessarily. I can as easily just simply modify existing ones and change the order. Remove the primary one, and add a new one (in the last case with the example. I will typically have up to 3 SortKeys. The example is nothing new - been there, done that many times in many projects. :) +1 for the willing to help anyway. :) – DejanLekic Jul 22 '13 at 11:15
  • no idea whats your goal, look here [Multisort Table Header Cell Renderer](http://tips4java.wordpress.com/2010/08/29/multisort-table-header-cell-renderer/) – mKorbel Jul 22 '13 at 11:24
  • Is it not obvious from the simple example I have above? :) Ok, let me try to explain using the latest example you gave - run the app from the article http://tips4java.wordpress.com/2010/08/29/multisort-table-header-cell-renderer/ and setup the max number of SortKeys to 3, then click on a column that is NOT sorted yet. You will see that the column got the PRIMARY SortKey - I DO NOT WANT THAT! :) After that, check my ASCII example, and see how I want it to behave instead. :D – DejanLekic Jul 22 '13 at 13:30
  • still not clear, issue is in sorting order in columns or ..., better could be to post an SSCCE with description to every of columns what will be happens – mKorbel Jul 22 '13 at 13:39
  • Nah, forget it, thanks anyway. I can't do SSCCE for every simple question I have. :) I have to work. The simple SSCCE would be a normal JTable with setMaxSortKeys(3); and after that make any column to be sorted, and after that simply click on ANY non-sorted column. - It will become the primary sorted column. That is totally ridiculous behaviour, and I want to change that so the secondary one becomes primary, third becomes second, etc... :) I will clean up my TableHeader and post it here as an example of how I did it. Probably tomorrow... – DejanLekic Jul 22 '13 at 13:51