I have looked on these forums and on the net for the answer to this question. The problem seems quite common, but I can't find the solution.
On my JTable I have a TableCellEditor. It is working for every cell except the final cell that gets edited before the table loses focus. For example, if I edit a cell and then click a button, that specific edit does not get saved.
Where does this get processed so that I can catch it?
When you say "write in a cell" I'm assuming that you mean column 1 and not column 0 (since that is what you are printing).
I can't say I'm entirely clear why you are using this call in your code:
If you have built this table from the contents of your "rows" object, then I might suggest that you use fireTableDataChanged() in your setData() method.
Also, check to make sure that this statement:
isn't returning a null under some condition.
Joined: May 18, 2004
I just wanted to say thanks for the help you are giving to help me get this right. I very much appreciate it!
I changed the code to use the fireTableDataChanged and not I don't have to catch that null pointer exception in the tableChanged anymore. So that's cool.
Yes, only column is editable.
The getDestinationKeyPair doesn't return a null at any time.
So after those additions these are the results in the four scenarios... 1 - Edit cell and click to another cell - Works 2 - Edit cell and click close (calling system.exit) - Works 3 - Edit cell and click x button - Doesn't work but I've decided that that's right so we'll forget this one.
So the last scenario to get working is the following. On my app, there is a list. When clicking on the list, the table is changed to show the information that is detailed by the item that is selected in the list. What is happening now is that when the user edits a cell and then clicks on the item in the list, I then get an ArrayOutOfBounds Exception in the setValue of the table model. I have a feeling that this is because the data in the table is changing at that moment so I'm going to try and get the click on the list to first save the changes and then show the new table data.
Do you think my suspicions sound right?
Cheers, and many many thanks again! Rachel
Joined: May 18, 2004
Yes, it did work. I told the TableCellEditor to stopEditing whenever I click on the list. It's not the best way to do it I'm sure, but it works!
Thanks for putting up with me being slow about this.