• Post Reply Bookmark Topic Watch Topic
  • New Topic

getValueAt doesn't pick up changes  RSS feed

 
Rick Portugal
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building a screen that has a JTable and a "save" button. The user can enter values in the cells of the JTable and press "save" to save them in the database.

Sometimes the user enters a value in a cell and presses the "save" button without tabbing off of that cell first. In this case, the getValueAt() method doesn't recognize that the cell's value has been changed.

Is there another method that I can use instead of getValueAt() to get the new changed value? Maybe reallyGetValueAt()?
 
Rick Portugal
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know how to get the value in a cell even if the user hasn't pressed enter of tabbed off the cell yet? I imagine that is something that needs to be done a lot.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This situation is a problem because until the user hits 'enter' or tabs out of the cell, the JTable doesn't know to update the model. If you look at the documentation for JTable, you will see that it has several methods to determine if it is being edited (isEditing()),the coordinates the edit is taking place (getEditingRow/Column) and what component is doing the editing (getEditingComponent()).
Wherever you do your "save" button logic, I'd check isEditing(). If it returns true, I'd use the other methods to determine the value the user typed in and update the model with it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!