Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jtable sorting; problem with getValueAt

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • 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

 
Brian Cole
Author
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked about getColumnClass(), not getColumnName().
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • 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)
{

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic