• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable saving data question

 
Daniel Roach
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an editable JTable which uses a class which extends the AbstractTableModel as the data model. I have methods which save the data from the model into a file. How can I be sure that all the changes to the JTable are reflected in the model? I am using the DefaultCellEditor to edit the cells.
Any help would be very much appreciated.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changes may not be made to the table model if a cell is still being edited.
I think by default (someone correct me if I'm wrong) the value won't actually get set until you hit enter in the cell or move focus away.
If you put a print statement in your model's setValue(), you should be able to see when this happens.
Are you experiencing a loss of data?
Bill
 
kishore pendyala
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, Bill is correct, if the table is still in editing mode, then that particular cells value will not be reflected in your data model. The solution to this problem is to write a method which does the following in sequence.
1. check if table is in editing mode(use jtable API).
2. if true, get the particular cell value, update your data model with the value and then remove cell editor using api call.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!