This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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.
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.
Joined: Jun 14, 2004
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.
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?
Joined: Jul 17, 2004
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 ]