Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

caching TableModelListener data for updates  RSS feed

 
Tim Nachreiner
Ranch Hand
Posts: 36
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my understanding of how a JTable and respective DB table would be updated via directly editing a JTable: After table cell is updated, the setValueAt method of my custom TableModel is called to change the value of the data vector (assume I'm using vectors to store data). setValueAt then calls fireTableCellUpdated which updates the table view, and calls my custom TableModelListener.tableChanged method. Here is where I would write code to update the database.

This means an Update statement is fired each time a cell changes. Sometimes I would like to only send the Update after the entire record has been updated (and a user clicks a Save button). Any idea how I would implement this variation?
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometimes I would like to only send the Update after the entire record has been updated (and a user clicks a Save button). Any idea how I would implement this variation?


You can add another column of data to the TableModel that contains a Boolean value. This column would not be displayed on the view of the JTable. Then whenever a TableModelEvent is generated you set the Boolean value to true for the row.

When the user clicks on the "Save" button you iterate through all the row in the TableModel and save the data in the rows that contain a true Boolean value.

If you don't want to add extra data to the TableModel you could also create a "Set" that contains the Integer value of the rows that have been changed.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!