• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cells on JTable are editable but revert back to original value.

 
rui sanches
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program reads a txt file, presents the information in a jtable, and allows for filtering of it. It also needs, and this is what I cant figure out, to allow for the cells to be edited and then save the alterations back to the txt file.
Now, I dont really know much about java, my program was made based on numerous suggestions from all over the internet. What Im looking for here is some input as to why my cell editing isnt working, and how to save any information changes back to the txt file.

Any help would be appreciated.

 
Campbell Ritchie
Sheriff
Posts: 52055
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I can never remember anything about tables, so have a look in the Java™ Tutorials. Basically, you have a table which is backed by a model. You want changes in the table to update the model. You can't update the text file; you can only read and write in the text file. Update the model and then when you finish your session, write all the model into a text file. You can either overwrite the whole text file or append to it but you cannot update parts of the text file.
 
Knute Snortum
Sheriff
Posts: 3137
79
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Just a note about your post.  Thank you for using code tags.  Remember to include your import statements with your code.
 
Knute Snortum
Sheriff
Posts: 3137
79
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After your while loop, at line 74 or so, I'd close bufReader or you'll have a resource leak.
 
rui sanches
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the list of imports. Thanks for the reminder.

 
Brian Cole
Author
Ranch Hand
Posts: 916
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The signature of your table model's setValueAt() method is incorrect, so it's not overriding the setValueAt() method defined in AbstractTableModel. If you had used the @Override annotation for this method (like you did for a couple of other methods in your table model) then the compiler would have shown you an error message and you would have known where the problem was.

So you need to remove the bogus fourth argument to your setValueAt() method. Then you need to correct its implementation. You will want it to call something like list.get(rowIndex).setXXXX(). The call to fireTableCellUpdated() should remain.


Btw, minor issue but naming conventions call for class names to begin with a capital letter, so testone -> Testone.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!