I'm trying to display dates in a table and also have these dates sorted. Unfortunately, the extra catch is that I want the date to be formatted as just the dayname, month, day, and year (I don't want any time values). So, in my table for getValueAt(i,j) I return a DateFormat formatted
string to display what I want. However, this returns a String object which screws up the comparator. eg: "Sunday July 15 2001" can actually be greater than "Monday September 18, 2004". 'S' is greater than 'M' but obviously 2004 is greater than 2001!
So, I think this kind of a silly way to do what I want. I created a new class called SimpleDate. It has a member called date of type java.util.Date. When I create a SimpleDate object, I have a Date object (such as from Calendar.getInstance().getTime()) and store it. My toString() method will display the date formatted the way I like. I made SimpleDate implement Comparable and I have a compareTo method which returns: this.date.compareTo(anotherSimpleDate.date)
(assuming all the objects are not null, etc)
Ideally, this will allow me to return a SimpleDate object in getValueAt(i,j) in my table model that is displayed properly and sorts correctly.
The sorting ability in my table is still messed up though. Can anyone suggest a better solution or any gotchas as to what might be wrong with my solution? I thought about displaying numbers like (2004/10/05) which makes the String comparable in the correct way but it doesn't look good so I don't want that.
Thanks.
[ September 24, 2004: Message edited by: Darien Cheung ]