• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting problem of Date column in Jtable

 
Helen Dong
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
searching first will generally produce solutions

http://www.coderanch.com/t/563518/GUI/java/Trouble-JTable-sorting-dates
 
Helen Dong
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic