Results 1 to 2 of 2
  1. #1
    mattj is offline Member
    Join Date
    Sep 2008
    Rep Power

    Default sorting Dates with TableSorter

    I have made a sorter and a table using

    Java Code:
    model =new DefaultTableModel();
    sorter = new TableSorter(model);
    table = new JTable(sorter);
    And i have 6 columns with the following types

    Integer, String, String, String (representing a Date), String (representing a Date), double

    And the problem is, since i used SimpleDateFormat to format my dates into dd/MM/yyyy they are of type String in the table. I want to know how i can write a comparator that sorts the dates correctly, and also how to implement it with available from

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Writing a comparator shouldn't be too dificult; you have to parse the string and do some Calendar/Date math.
    I would leave the Date types in the TableModel (and let java do the math), set a custom renderer on the two Date columns and use your SimpleDateFormat to format the Date values in the renderer.

Similar Threads

  1. TableSorter
    By mattj in forum New To Java
    Replies: 3
    Last Post: 09-16-2008, 10:48 PM
  2. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 07:05 AM
  3. No fo days between two dates
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-28-2008, 09:06 AM
  4. help with dates and time
    By osval in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 12:41 PM
  5. differences between 2 dates
    By cecily in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 05:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts