Swing JTable updating

B

Big Dave Smith

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.
 
M

Michael Rauscher

Big said:
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
 
B

Big Dave Smith

Michael said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top