This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable Cell Values reapeated in all Model rows

 
Rw Adams
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java Ranchers,

I have run into a problem that has me stumped.... I am writing a simple menu planner with a database for the storage of meals and ingredients. I use a JTable to enter the Ingredients for each meal. The problem I am running into seems to be when I enter a value for the Ingredient (column #2 with 0 as the first column), that value is being repeated for all rows in the model. I have used my Netbeans debugger and I THINK I have narrowed things down to the setValueAt method of my table model. I say THINK because I just don't see how this problem is occuring...



The rowArray.set() call on line 10 seems to be the culprit, I.E The values in the model are null before that call is made and are null, and the values in the model after the call are the same as the value I entered for the Ingredient. I don't understand how the entire model in the rowData field is being updated with the repeated value? I also don't have a clue on where/how to about tracking down what is causing this problem...
Any ideas/suggestions are appreciated.

Wanted to add these as attachments but the .txt,.java,and .jav extensions are not allowed?

Thanks for the help!

PanelCode:



Model Code:
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your initModel() method is adding the same ArrayList object to each row so any change in any row will be seen in all rows.
BTW your addRow method isn't calling fireTableRowsInserted();
 
Rw Adams
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DUH! It took me 20 minutes of staring at initModel() to finally see my mistake. Another hour of fixing the code I thought was working and that fixed it.

Thank You!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic