Swing JTable updating

Discussion in 'Java' started by Big Dave Smith, Dec 14, 2006.

  1. I'm new to swing, and I've run into a slight problem. I'm sure it's
    simple, but I have not the knowledge to fix it.

    I have a JTable, created using two Vectors. The vectors change every
    so often based on other events in the gui, so the columns change. I'm
    not sure what the proper way to update the table is, however. Do I
    just rerun the createTable() method I've written, and then add it to
    the layout manager again, and it replaces the old table? It seems like
    there should be a cleaner and simpler way to do that.

    Thanks for any help you can offer. I've been using Java for years now,
    but this is my first week with Swing.
    Big Dave Smith, Dec 14, 2006
    #1
    1. Advertising

  2. Big Dave Smith schrieb:
    > I'm new to swing, and I've run into a slight problem. I'm sure it's
    > simple, but I have not the knowledge to fix it.
    >
    > I have a JTable, created using two Vectors. The vectors change every
    > so often based on other events in the gui, so the columns change. I'm
    > not sure what the proper way to update the table is, however. Do I
    > just rerun the createTable() method I've written, and then add it to
    > the layout manager again, and it replaces the old table? It seems like
    > there should be a cleaner and simpler way to do that.


    Just fire the appropriate events (see AbstractTableModel#fireXXX).

    Bye
    Michael
    Michael Rauscher, Dec 14, 2006
    #2
    1. Advertising

  3. Michael Rauscher wrote:
    > Big Dave Smith schrieb:
    > > I'm new to swing, and I've run into a slight problem. I'm sure it's
    > > simple, but I have not the knowledge to fix it.
    > >
    > > I have a JTable, created using two Vectors. The vectors change every
    > > so often based on other events in the gui, so the columns change. I'm
    > > not sure what the proper way to update the table is, however. Do I
    > > just rerun the createTable() method I've written, and then add it to
    > > the layout manager again, and it replaces the old table? It seems like
    > > there should be a cleaner and simpler way to do that.

    >
    > Just fire the appropriate events (see AbstractTableModel#fireXXX).


    Thanks! This is helpful, I know a bit more about how tables operate
    now. I think I need to rephrase my question, however. The data is not
    actually changing in my table, I just want to hide or show columns
    based on checkboxes in a menu, because not every user will care about
    every column.

    Is the best way to do this still by modifying the data, and notifying
    the model that the table has changed? It seems like an expensive
    operation to just hide data. If I could
    TableModel.setColumnVisible(int, boolean) or something like that, it
    seems like it would be a lot quicker. I just have a lot of data, and
    don't want to muck with it each time I show or hide a column. Thanks
    again!
    Big Dave Smith, Dec 16, 2006
    #3
    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. Tivo Escobar
    Replies:
    1
    Views:
    7,266
    manusa
    Apr 12, 2007
  2. mkrause
    Replies:
    0
    Views:
    661
    mkrause
    May 6, 2005
  3. Tintin92
    Replies:
    1
    Views:
    1,672
    Andrew Thompson
    Feb 14, 2007
  4. news.rcn.com
    Replies:
    2
    Views:
    1,104
    Roedy Green
    Dec 10, 2007
  5. Haircuts Are Important
    Replies:
    3
    Views:
    296
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page