Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6210779

Auto transfer of focus when removing component causes problems in JTable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P4 P4
    • None
    • 1.4.0, 6
    • client-libs
    • x86
    • windows_98, windows_nt, windows_xp

      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

            Unassigned Unassigned
            shickeysunw Shannon Hickey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: