Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jtable sorting; problem with getValueAt

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I have implimeneted a sorting JTree (with a TableSorter).
Problem is when the user clicks on the column, say length, the sorting is incorrect. (it sorts it as if it's a String; same goes to the sort by dueDate)

I understand that the sorting is according to the object's type. the due date is a String in the example below but when converting to Date, the result is: Wed Aug 10 00:00:00 PDT 2005) (?!)

anyone knows how to correct this?
Thanks
Peter

 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which table sorter are you using? I guess the one
from the JFC demo is the most common, but there
are a few out there.

Also, what are you doing in your implementation
of the getColumnClass() method?
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public String getColumnName(int column)
{
return names[column].toString();
}

protected TableModel dataModel = new AbstractTableModel()...
TableSorter sorter = new TableSorter(dataModel);
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I asked about getColumnClass(), not getColumnName().
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mmm, good question. I didn't implement it.
is this the source of the problem?

what should be returned?

public Class getColumnClass(int col)
{

}
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic