my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes JTable Focus differences in Java version 1.4 vs 1.5+ when editing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable Focus differences in Java version 1.4 vs 1.5+ when editing" Watch "JTable Focus differences in Java version 1.4 vs 1.5+ when editing" New topic
Author

JTable Focus differences in Java version 1.4 vs 1.5+ when editing

J Belcher
Greenhorn

Joined: Jul 04, 2009
Posts: 2
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.

Solutions?
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.

Thanks guys.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Enter one of the badly documented features of Swing:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
J Belcher
Greenhorn

Joined: Jul 04, 2009
Posts: 2
Rob: Thanks a lot! I wonder why I couldn't find this fix anywhere else.
 
GeeCON Prague 2014
 
subject: JTable Focus differences in Java version 1.4 vs 1.5+ when editing