-
TableModel.getColumnClass()
Hi, anybody here has ever encountered and problem like mine? Please help if
you do.
I have an JTable and the table model derived from AbstractTableModel, I use
TableSorter from the tutorial to sort the table(I have also implemented my
own sorting method, but the result is the same), but whatever the data type
of the table column, the getColumnClass() method always return String type,
so the table is always sorted by String type.
My implementation of this method is as following:
return getValueAt(0, columnIndex).getClass();
What is possibly wrong? Any working around of this?
Please help, thank you so much!
Janet
-
Re: TableModel.getColumnClass()
That should work correctly, provided your implementation of the getValueAt()
method doesn't always return a String object. Does it?
PC2
"Janet" <kfsong@bsp.com.sg> wrote in message
news:3b554007$1@news.devx.com...
>
> Hi, anybody here has ever encountered and problem like mine? Please help
if
> you do.
> I have an JTable and the table model derived from AbstractTableModel, I
use
> TableSorter from the tutorial to sort the table(I have also implemented my
> own sorting method, but the result is the same), but whatever the data
type
> of the table column, the getColumnClass() method always return String
type,
> so the table is always sorted by String type.
> My implementation of this method is as following:
> return getValueAt(0, columnIndex).getClass();
> What is possibly wrong? Any working around of this?
>
> Please help, thank you so much!
>
> Janet
-
Re: TableModel.getColumnClass()
Janet,
The problem you are seeing is not with the getValueAt method, but with the
getColumnClass method. The getColumnClass method in AbstractTableModel always
returns String as the class for a column. This is why your sorter is having
problems, as it will always sort the column as though it is a String, which
isnt the correct order for numbers dates etc. What you need to do is in
you table model, override the getValueAt method to return the correct Class
for each column. This will enable your sorter to work correctly.
Hope that helps.
"Janet" <kfsong@bsp.com.sg> wrote:
>
>Hi, anybody here has ever encountered and problem like mine? Please help
if
>you do.
>I have an JTable and the table model derived from AbstractTableModel, I
use
>TableSorter from the tutorial to sort the table(I have also implemented
my
>own sorting method, but the result is the same), but whatever the data type
>of the table column, the getColumnClass() method always return String type,
>so the table is always sorted by String type.
>My implementation of this method is as following:
>return getValueAt(0, columnIndex).getClass();
>What is possibly wrong? Any working around of this?
>
>Please help, thank you so much!
>
>Janet
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks