Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Swing JTable updating

Reply
Thread Tools

Swing JTable updating

 
 
Big Dave Smith
Guest
Posts: n/a
 
      12-14-2006
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.

 
Reply With Quote
 
 
 
 
Michael Rauscher
Guest
Posts: n/a
 
      12-14-2006
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
 
Reply With Quote
 
 
 
 
Big Dave Smith
Guest
Posts: n/a
 
      12-16-2006
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating JTable Atomically - block data changes while updating. news.rcn.com Java 2 12-10-2007 11:49 AM
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Swing Model Classes Updating Swing Components on a Thread Other Than AWT mkrause Java 0 05-06-2005 04:32 PM
How to do a good use of JTable Swing ? Florent Coué Java 1 09-09-2003 02:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57