JDK-6210779 : Auto transfer of focus when removing component causes problems in JTable
  • Type: Bug
  • Status: Open
  • Resolution: Unresolved
  • Component: client-libs
  • Sub-Component: javax.swing
  • Priority: P4
  • Affected Version: 1.4.0,6
  • OS: windows_98,windows_nt,windows_xp
  • CPU: x86
  • Submit Date: 2004-12-20
  • Updated Date: 2017-05-23
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
One of the things that makes it difficult to fix certain bugs in JTable is AWTs auto transfer of focus when a component is removed from the hierarchy. Consider the following two test cases:

1) TestSpinnerEditorProblem.java (attached):
Compile and run the program.
Click in the top left cell and a spinner appears.
Click in the bottom left cell - the spinner appears quickly and then dissapears.

When the property "terminateEditOnFocusLost" is turned on, we have a listener that removes the editor when focus is moved somewhere outside the table. Here's what's happening:

Spinner is removed from table.
AWT does an auto transfer of focus due to the remove.
Spinner is added again to table in the new place.
Due to the asynchronous nature of focus notifications, we are notified after the spinner is added again about this focus change. As a result, the editor is removed.

2) Launch SwingSet2 and switch to the table demo.
Click on one of the combo box cells and the combo pops up.
Click on another of the cells - the combo pops up and then hides.

Again, this occurs again because AWT transfers focus somewhere else automatically in between and when we're notified later, the popup is cancelled.

I suspect there are work-arounds to all of this. For example, to fix #1 we could create a traversal policy such that the autotransfer goes to the table. However, all of these could be fixed with API that tells AWT not to auto transfer focus. (Additionally, we'd have to revert the change to 4887999 to fix the combo box problem demonstrated with SwingSet2 - we'd then need to seek a new fix for that bug).
###@###.### 2004-12-20 19:49:58 GMT

EVALUATION The bug 6180261 "Focus error when disabling in focus JTextField from TreeSelectionListener" is related to the same problem - auto focus transfer. We may provide user with an ability to forbid auto focus transferring, either on particular component or in focus policy itself. ###@###.### 2004-12-21 16:07:50 GMT