United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6358882 : JTable sorting behavior: Double clicking on header does not sort.

Details
Type:
Bug
Submit Date:
2005-12-05
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2006-03-16
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
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.setColumnSelectionAllowed(false);
 tbl_movies.setRowSelectionAllowed(false);
 tbl_movies.setCellSelectionEnabled(true);
 tbl_movies.setRowHeight(25);
 tbl_movies.setRowSorter(new TableRowSorter(dft));
 JScrollPane jsp = new JScrollPane();
 jsp.getViewport().add(tbl_movies);
 jsp.setSize(600, 250);
 this.add(jsp);
}
public static void main(String args[]) {
 JFrame jf = new JFrame();
 jf.add(new IAMATEST());
 jf.setSize(800, 400);
 jf.setVisible(true);
}
}

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

                                    

Comments
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.
                                     
2005-12-08
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.
                                     
2006-02-21



Hardware and Software, Engineered to Work Together