Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
J Belcher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enter one of the badly documented features of Swing:
 
J Belcher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob: Thanks a lot! I wonder why I couldn't find this fix anywhere else.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic