Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Swing JTable updating (http://www.velocityreviews.com/forums/t389429-swing-jtable-updating.html)

Big Dave Smith 12-14-2006 07:43 PM

Swing JTable updating
 
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.


Michael Rauscher 12-14-2006 10:03 PM

Re: Swing JTable updating
 
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

Big Dave Smith 12-16-2006 05:06 PM

Re: Swing JTable updating
 
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!



All times are GMT. The time now is 04:16 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.