JTable Focus differences in Java version 1.4 vs 1.5+ when editing
Joined: Jul 04, 2009
A little late to the dance here, but I've just now dived into finding out why my JTable editing stopped working when I upgraded from Java 1.4 to 1.5 and beyond. I'll post my question first, then the info I know.
The Problem (Upgrading from 1.4 to 1.5 caused my editable JTable to stop working)
Basically, I have an editable JTable which uses a large JPanel w/ lots of input controls (drop baxes, JTextBoxes, etc) for a custom editor (editPanel). That is, editPanel is the custom editor upon which my users are entering their data. The JTable itself is contained by another JPanel with other input controls (infoPanel). Whenever I leave (lose focus) from the JTable while editing the editPanel, I want the editing to stop.
In 1.4 it was easy enough to put a FocusListener on the JTable itself, and call the stopCellEditing method when the JTable loses focus.
Enter 1.5. The behavior is different here and the results were rather strange in that the JTable no longer gets focus when it is editing. Hence, I cannot use the FocusListener in the same way.
The info I've found
From what I've been able to gather, Sun made several changes regarding the focusTraversal methodology in 1.5 that, in my case, causes something in the editor to gain the focus and not the JTable itself (although I'm led to believe that the JTable momentarily gets the focus before giving it to the editor). So, I understand how it's happening, and to a much lesser extent why Sun made the change.
I'm interested to know if anyone else has come across this problem and how they're handling it. Some of the more obvious work-arounds would be to stop editing when something else gets the focus, but I have many controls on infoPanel and that's a little inefficient. I thought maybe I could see if the user clicks on a coordinate outside of the table and call stopCellEditing() (although I'm not positive how to do that.)
So far, I've had to keep building on 1.4.