JTables and dynamically adding data

Discussion in 'Java' started by michael.miceli88@gmail.com, Apr 26, 2008.

  1. Guest

    Hey,
    I have a JTable that I want to add a new column to every time someone
    clicks a button. I have been reading about extending the
    AbstractTableModel, but I don't how this allows you to add a new
    column. The examples online show what happens when a user edits a
    table, but I don't want that. I want it add when the user presses a
    button outside of the table. Some advice would be appreciated.

    Thanks
    , Apr 26, 2008
    #1
    1. Advertising

  2. Guest

    On Apr 26, 1:46 pm, RedGrittyBrick <>
    wrote:
    > wrote:
    > > Hey,
    > > I have a JTable that I want to add a new column to every time someone
    > > clicks a button. I have been reading about extending the
    > > AbstractTableModel, but I don't how this allows you to add a new
    > > column. The examples online show what happens when a user edits a
    > > table, but I don't want that. I want it add when the user presses a
    > > button outside of the table. Some advice would be appreciated.

    >
    > Have you tried incrementing the value returned by your getColumnCount(),
    > making sure getValueAt() now returns the appropriate values then calling
    > fireTableStructureChanged()?
    >
    > --
    > RGB


    No, but I will give this a try, and hopefully get back to you by the
    end of the day.
    Thanks
    , Apr 26, 2008
    #2
    1. Advertising

  3. Guest

    On Apr 26, 2:16 pm, wrote:
    > On Apr 26, 1:46 pm, RedGrittyBrick <>
    > wrote:
    >
    > > wrote:
    > > > Hey,
    > > > I have a JTable that I want to add a new column to every time someone
    > > > clicks a button. I have been reading about extending the
    > > > AbstractTableModel, but I don't how this allows you to add a new
    > > > column. The examples online show what happens when a user edits a
    > > > table, but I don't want that. I want it add when the user presses a
    > > > button outside of the table. Some advice would be appreciated.

    >
    > > Have you tried incrementing the value returned by your getColumnCount(),
    > > making sure getValueAt() now returns the appropriate values then calling
    > > fireTableStructureChanged()?

    >
    > > --
    > > RGB

    >
    > No, but I will give this a try, and hopefully get back to you by the
    > end of the day.
    > Thanks


    Yes this worked thank you!
    , Apr 27, 2008
    #3
  4. Roedy Green Guest

    On Sat, 26 Apr 2008 11:28:31 -0700 (PDT),
    wrote, quoted or indirectly quoted someone who said :

    >The examples online show what happens when a user edits a
    >table, but I don't want that. I want it add when the user presses a
    >button outside of the table. Some advice would be appreciated.


    You would have to both modify your TableModel to add the data, and
    tell the GUI JTable part you have a new column. You would add it just
    the way you would add a column to start.

    See http://mindprod.com/jgloss/jtable.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Apr 27, 2008
    #4
  5. every time you want to change it just create a new model and use the
    setModel function in the JTable class to update the UI
    Chase Preuninger, Apr 27, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. G.Schiber

    an array of JTables

    G.Schiber, Sep 14, 2003, in forum: Java
    Replies:
    3
    Views:
    803
    Matt Humphrey
    Sep 15, 2003
  2. BNM

    JButtons in JTables

    BNM, Jan 30, 2004, in forum: Java
    Replies:
    0
    Views:
    470
  3. freesoft_2000

    JTables

    freesoft_2000, Feb 8, 2005, in forum: Java
    Replies:
    1
    Views:
    681
    Andrew Thompson
    Feb 9, 2005
  4. freesoft_2000

    JTables

    freesoft_2000, Jun 23, 2005, in forum: Java
    Replies:
    1
    Views:
    523
    Andrew Thompson
    Jul 4, 2005
  5. Replies:
    1
    Views:
    344
    VisionSet
    Mar 7, 2006
Loading...

Share This Page