File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Sorting problem of Date column in Jtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Sorting problem of Date column in Jtable " Watch "Sorting problem of Date column in Jtable " New topic
Author

Sorting problem of Date column in Jtable

Helen Dong
Greenhorn

Joined: Jan 15, 2013
Posts: 2
Hello, I have an issue with sorting Date column in Jtable which is sort by String type.
How can I achive sorting Date column by click column header?
Please help!
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
searching first will generally produce solutions

http://www.coderanch.com/t/563518/GUI/java/Trouble-JTable-sorting-dates
Helen Dong
Greenhorn

Joined: Jan 15, 2013
Posts: 2
Thanks Michael.

Firsr I use getColumnClass to convert String type to Date type, and Date shows as Mon dd, yyyy.
Then use DefaultTableCellRenderer to format to MM/dd/yyyy.

But CellRenderer will skip the column that has change class type.

Do you know how to solve this issue?
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1088
    
  10

Hi Helen,
Welcome to the Ranch!

Are you having the data as a String in your model? In the post link that was provided, you can see that it is recommended to hold the values as 'Date' objects in the model. When that is done, rendering is automatically done by displaying the date in the short format. If you still need your own renderer, you can do that with table.setDefaultRenderer which takes a 'class' type as the first argument.
You can checkout this tutorial page to know more about this.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting problem of Date column in Jtable