1

I use JXTable and JXTableHeader to display sortable tables. JXTableHeader supported a way to reset sort order, by holding down shift and left clicking on the headers at the same time. The problem is the following: This reset mode is not possible atm, becuse Java Swing's BasicTableHeaderUI adds a mouse listener to JXTableHeader and eventhough I add my own listener to JXTableHeader, BasicTableHeaderUI's gets triggered and although I reset sort order in my listener's mouseClick method, the BasicTableHeaderUI's immediately sets the same column to be sorted in its own mouseClick method. Problem #2, I cannot use consume on the event, since BasicTableHeaderUI's listener just ignores the flag.

How can I prevent BasicTableHeaderUI's listener to be triggered in a clean way?

Solution:

This is the solution I went with. I implemented a wrapper for the BasicTableHeaderUI's MouseListener and changed that to my wrapper on updateUI. My wrapper just ignores the wrapped MouseListener's mouseClick call on a certain condition (-> resetSortOrder).

Community
  • 1
  • 1
user1405469
  • 195
  • 9
  • 1
    Also see [this question](http://stackoverflow.com/questions/9532044/jxtable-column-sorting-changes-between-1-0-and-1-6) – Robin Mar 04 '13 at 16:21
  • 1
    `table.setSortOrderCycle(ASCENDING, DESCENDING, UNSORTED);` – Guillaume Polet Mar 04 '13 at 16:22
  • 1
    remove all MouseListener from JTableHeader, all MouseEvent and KeyEvents can be evt.consume(), or redirected, or fireXxxXxxx, for workaround and code search in post by @kleopatra, [a few times answered](http://stackoverflow.com/search?tab=newest&q=user%3a203657%20[jtable]) – mKorbel Mar 04 '13 at 18:20
  • Thanks mKorbel, something like [this](http://stackoverflow.com/questions/14437547/sort-jtable-when-mouse-released/14439616#14439616) might actually work, not so nice thou ... – user1405469 Mar 04 '13 at 20:06
  • Thanks Robin and Guillaume, but I really need the original behaviour ... – user1405469 Mar 04 '13 at 20:11
  • beware: such hooking might not work with JXTableHeader because it does some magic - to not sort if in the resizing area - internally (using a private mouseListener) - not sure how/if that one might interfere, never tried :-) – kleopatra Mar 05 '13 at 13:37

0 Answers0