JDK-6358882 : JTable sorting behavior: Double clicking on header does not sort.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-12-05
  • Updated: 2010-04-02
  • Resolved: 2006-03-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
6 b76Fixed
Steps to reroduce:
Compile and run the attached testcase. 
Double clik on the header of the table, multiple times. 
Observed behavior 
Nothing happens, the table is not sorted. 
Note:This behavior can sometimes be slightly itermittent, depending on the clicking speed of the user.
Expected behavior 
The table should get sorted. 
on Windows, in the windows file explorer, double cliking sorts the file view. 
The end user would expect the same in Jtable. One of the motivation of this table feature was to allow sorting through java api as in an explorer and thereby get closer to native behavior. 
----------BEGIN SOURCE----------

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.table.TableCellEditor.*;
import java.awt.event.*;
import java.awt.event.KeyEvent.*;
class IAMATEST extends JPanel {
public IAMATEST() {
 String table_data[][] = { {"Comedy", "Kindergarten Cop", "1990"},
 {"SciFi", "Total Recall", "1990"},
 {"Action", "Eraser", "1996"} };
 String column_headers[] = {"Genre", "Title", "Year"};
 String combo_items[] = {"Stallone","Schwarzenegger"};
 DefaultTableModel dft = new DefaultTableModel(table_data, column_headers);
 JTable tbl_movies = new JTable(new DefaultTableModel(table_data, column_headers));
 tbl_movies.setRowSorter(new TableRowSorter(dft));
 JScrollPane jsp = new JScrollPane();
 jsp.setSize(600, 250);
public static void main(String args[]) {
 JFrame jf = new JFrame();
 jf.add(new IAMATEST());
 jf.setSize(800, 400);

----------END SOURCE------------

EVALUATION Verified with customer and Explorer that Windows sort on every odd number click. We currently only sort on the first click. The fix is to check for clickCount % 2 == 1.

EVALUATION With explorer try clicking the mouse on a header, holding it down, then release it. Notice that the column sorts. So, it's the first click that sorts, not the second. The difference appears to be we sort on single click, not on release. We may need to instead sort on the first release.