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

KeyEvents dispatched to old focus owner that is no longer showing

XMLWordPrintable

    • beta3
    • sparc
    • solaris_7

      Run the attached test case, type alt 'o' to bring up the first menu, then alt t to bring up the second menu. It will appear that the second menu never came up, but instead the mnemonic for one of its children was used and the ActionListener was notified.
      Here is the sequence of events that happen when a menu goes down and a new one comes up (this is in my evaluation for 4472032):
      1. when the menu becomes visible focus is transfered to the JPopupMenu, the current focus owner is recorded.
      2. An ancestor* of the popup menu is removed from the containment hiearchy, resulting in focus being transfered (via the nextFocusHelper method)
      3. the hidden popup menu installs focus on the recorded focus owner (the button).
      4. a new popup menu comes up resulting in requesting focus on the newly visible JPopupMenu.

      * JPopupMenu uses a Popup (doesn't descend from Component, but will choose the appropriate type of Component subclass based on space and the developers requirement) to display itself. In the case where the popup doesn't fit in the containing window, a Window is used to host the JPopupMenu vs a JPanel if the JPopupMenu fits.

      The menu processes the KeyEvent on the pressed event, and the mnemonic on the typed event. We have code that will ignore the typed event in certain cases. When you press alt-t it causes steps 1-4 to occur above. But it also appears that the typed and released KeyEvents end up going to the first popup that is now hidden and no longer the focus owner. This is what is causing Swing to activate the mnemonic on the pressed event because we assume the keyTyped event will only be seen if the component is showing.

      This may be related to 4472032.

            son Oleg Sukhodolsky (Inactive)
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: