views:

388

answers:

2

When you edit a cell in an jtable the value is made permanent only if the focus is changed or if one hits enter (for example if you change the cell value from "abc" to "xyz" and close the window the edit is lost). How do i make the edit permanent when the user stops editing?

I guess we have to update the cell value as the cell value is being editted but i am not sure how. Any help is appreciated!

Thanks in advance!

+1  A: 

I would setup an ActionListener on the cell that saves the value of the cell to a variable after every keystroke (assuming the cell has focus). Then no matter what happens to the windows this variable will still contain whatever was currently in the cell. Pretty simple.

Gandalf
A: 
// tell JTable to stop editing and save any changes when the table
// loses focus. This means edits will be saved when clicking on 
// another component, eg: button.
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
tukushan