aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTables in JTabbedPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTables in JTabbedPane" Watch "JTables in JTabbedPane" New topic
Author

JTables in JTabbedPane

Allen Smith
Greenhorn

Joined: Jun 14, 2004
Posts: 11
I want to put JTables on tabs on a JTabbedPane. Since the tables are all going to display the same type of data I want to use the same tableModel. Unfortunately, when I use the same model I get data on multiple tables.

Here is how I am setting up the tables and populating the tabs:


Populating individual tables...


Need some help understanding how to use the same model without populating multiple tables.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18882
    
    8

Since the tables are all going to display the same type of data I want to use the same tableModel.
That isn't quite right. Since the tables are all going to display the same type of data you want to use the same type of tableModel. You do appear to be putting the same data into each of your table model instances, like this:The RHS of that expression doesn't depend on "i" and "columns" doesn't appear to change anywhere inside the loop.
Allen Smith
Greenhorn

Joined: Jun 14, 2004
Posts: 11
You are exactly right I want to use the same type of tableModel.

How do I get the same type of model??? I decided to use the array of models as a way of getting individual models, but obviously that isn't working.
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
hello,

apparently you are creating different instances. Maybe you are using only one of them, though. Or maybe you have static variables in the Transaction_Table class.

Kai


Kai Witte's business website Kai Witte's private homepage
Allen Smith
Greenhorn

Joined: Jun 14, 2004
Posts: 11
I am pretty sure that I am using the correct instance of the table, but when I add data to a second table, the information appears in both tables.

I found this quote on "The Java Developers Almanac: 1.4"

"When you share a table model between two table components, any changes made to values in the model will appear in both table components."

I want to have multiple tables that display the same type of data. I am obviously missing an easy concept here. Has anyone done this type of thing?
Kai Witte
Ranch Hand

Joined: Jul 17, 2004
Posts: 356
Yes, you are missing a simple concept - but that's all that I can say for sure from what you have provided. A static variable might be the cause, or not using close encapsulation. For example this "columns" reference you are using could be an array or Collection which could be used directly as the data backbone by the model without making a copy. In that case all models would contain the same data.

Speculation, but that's what you asked for if I understood your request. The relevant code that causes the problem might be the constructor of the table model and its instance variables - show it to us.

The quote from the The Java Developers Almanac you provided has nothing to do with the problem, because you are just using the same model class for multiple tables, not the same instance.

Kai
[ February 18, 2006: Message edited by: Kai Witte ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTables in JTabbedPane