Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6708418

Control over event to trigger sorting on a JTable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      A DESCRIPTION OF THE REQUEST :
      The way a JTable implements sorting, we can click on a column header and the table will sort by that column. The trouble is that I have no control over what the event modifiers may do. Right now, it will sort regardless of what modifiers I use, and there's no way to override this. If I want it to sort only on a click, but not on a shift click, I can't do this.

        To see this, run the test case. Try clicking using various combinations of modifier keys as you click. You can see that it always sorts, regardless of the modifiers. You may also choose a different look and feel to see that it doesn't depend on those. You may uncomment the Substance and Nimbus L & Fs if your version of the JRE allows them.

      JUSTIFICATION :
      Sorting when the user clicks is fine. But I may want to add more sophisticated features invoked through modifiers. For example, I may want shift-click to add the column to the previous sort. I may want shift-click to sort by a different characteristic of the column. Or I may want shift-click to do something unrelated to sorting, such as bring up a dialog for that column. There's no way to do this without also getting a sort.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would like a way to intercept the event that triggers sorting, so I may reject the sort operation, based on its modifiers. Ideally, this would come from a method that I can override, although I don't care if it's in the JTableHeader, the JTable, or the RowSorter. It could look like this:

      public boolean triggerSort(MouseEvent event);
      ACTUAL -
      There's no way to catch that event. I could write my own mouse listener and consume the event, but I have no guarantee that my mouse listener will get the event before sorting begins.


      ---------- BEGIN SOURCE ----------
      Attached seperatly
      ---------- END SOURCE ----------

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: