Results 1 to 4 of 4
  1. #1
    Friqenstein is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default jTable: Object to a double?

    Hello all,

    I'm working on a small GUI application and I've stumbled upon something I can't quite wrap my head around.

    I'm retrieving a value from a cell, or many cells actually, in a jTable with the following:
    Java Code:
    Object G1P1a = PeakBubTable.getValueAt(0,0);
    The jTable is setup so that the data entered is a double.
    However, when I retrieve the cell data it is an Object. I need to pass this retrieved cell data (i.e. 7.5, 2.3, etc) to a class that I've written.

    I'm getting an error stating that the method in my class cannot be applied to given types. I'm assuming this is because it is being retrieved as an Object, but needs to be a double in order to be utilized in my mathematical equations in my class.

    I couldn't find an example similar to what I'm doing. Most examples only show how to populate a table, or simple retrieve cell data and display it, but not actually do anything useful with it.

    Any help is greatly appreciated.
    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What happens if you cast the Object returned to Double type? For example:
    Java Code:
    Object objValue = PeakBubTable.getValueAt(0,0);
    double doubleValue = ((Double)objValue).doubleValue();

  3. #3
    Friqenstein is offline Member
    Join Date
    Aug 2010
    Posts
    7
    Rep Power
    0

    Default Solved.

    Fubarable,

    Thanks for the reply.

    That seems to have solved my issue. At first I was trying to simply pass the Object as a double, then I tried to force the Object into double type similar to what you suggested, but I was unfamiliar with how to do that.
    Much appreciated. :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. double a * double b = weird output
    By GPB in forum New To Java
    Replies: 3
    Last Post: 03-26-2010, 11:40 AM
  2. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 03:51 PM
  3. Replies: 5
    Last Post: 03-21-2009, 10:32 PM
  4. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 09:39 AM
  5. Replies: 2
    Last Post: 05-15-2008, 11:15 AM

Posting Permissions

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