• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable Cell Values reapeated in all Model rows

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic