Results 1 to 5 of 5
  1. #1
    TempExpt is offline Member
    Join Date
    Mar 2014
    Posts
    13
    Rep Power
    0

    Question How to add Computed column to TableModel at runtime ?

    Hello All,

    Could you please share suggestion/idea how can I add computed/derived column to an existing TableModel ?
    I've 7 column in the existing TableModel. Now I've to add 8th column and it'll be based on Col2, Col3 & Col5.
    Value of Col8 should be in following logic.

    public TableModel GetDerivedTable(ResultSet rs)
    {
    TableModel model = GetTable(rs); // I've done this


    //Now have to modify here

    If(Col2==true && Col5==true)
    Then{Col8 = 1}
    Else IF((Col2==true && Col5==false) || (Col2==false && Col5==true))
    Then{Col8 = Col3}
    Else IF(Col2==false && Col5==false)
    Then{Col8=-1}

    return model;
    }

    Any suggestion please...
    Last edited by TempExpt; 04-03-2014 at 09:35 AM.

  2. #2
    yuvijagdale is offline Member
    Join Date
    Mar 2014
    Posts
    3
    Rep Power
    0

    Default Re: How to add Computed column to TableModel at runtime ?

    by using ResultSet oject and in that use getColumnCount() method and traverse using for loop

  3. #3
    TempExpt is offline Member
    Join Date
    Mar 2014
    Posts
    13
    Rep Power
    0

    Default Re: How to add Computed column to TableModel at runtime ?

    Thank you for reply. Any sample code please ...

  4. #4
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: How to add Computed column to TableModel at runtime ?

    Not entirely sure what you really want to do. Considering the GetDerivedTable method takes in a ResultSet parameter, presumably you'll need to extract data from the ResultSet object in order to populate the TableModel. Have you done this already? The line "TableModel model = GetTable(rs);" tells me nothing...

    To extract data from ResultSet, and assuming this is the JDBC ResultSet, go through the JDBC trail at Trail: JDBC(TM) Database Access (The Java™ Tutorials). There's a specific section on operations with a ResultSet at Retrieving and Modifying Values from Result Sets (The Java™ Tutorials > JDBC(TM) Database Access > JDBC Basics). Familiarise yourself also with the ResultSet API at ResultSet (Java Platform SE 7 ). If you need to get a count of columns in the ResultSet, you'll need to first get the ResultSetMetaData before you can do so. Refer to the API doc for the method to use.

    Once you have extracted the data you need from the ResultSet, post here your code attempt at populating the TableModel. Please wrap your code with [code] tags so that it is easier to read, e.g.,
    [code]
    // your code here
    [/code]

    It preserves formatting and provides syntax highlighting, e.g.,
    Java Code:
    // your code here

  5. #5
    TempExpt is offline Member
    Join Date
    Mar 2014
    Posts
    13
    Rep Power
    0

    Default Re: How to add Computed column to TableModel at runtime ?

    I got it. Thank you.

Similar Threads

  1. Replies: 0
    Last Post: 10-18-2013, 07:03 PM
  2. Replies: 0
    Last Post: 01-17-2013, 01:43 PM
  3. how to get/call the computed value
    By shizuka in forum New To Java
    Replies: 1
    Last Post: 02-27-2011, 10:38 AM
  4. Replies: 1
    Last Post: 07-06-2010, 05:50 PM
  5. Map in TableModel
    By tiro in forum AWT / Swing
    Replies: 1
    Last Post: 07-01-2009, 08:53 AM

Tags for this Thread

Posting Permissions

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