File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTable Cell Values reapeated in all Model rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Cell Values reapeated in all Model rows" Watch "JTable Cell Values reapeated in all Model rows" New topic
Author

JTable Cell Values reapeated in all Model rows

Rw Adams
Greenhorn

Joined: Oct 28, 2011
Posts: 10
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

Joined: Aug 07, 2007
Posts: 2405
    
  50
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

Joined: Oct 28, 2011
Posts: 10
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
 
subject: JTable Cell Values reapeated in all Model rows