TableModel.getColumnClass()


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: TableModel.getColumnClass()

  1. #1
    Janet Guest

    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

  2. #2
    Paul Clapham Guest

    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




  3. #3
    Mans Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center