Some investigation showed the following.
When user hits Alt in IE focus goes into menu. This is triggered
on native level as well as what happens after user hits Alt the second time.
Somehow Windows retains previous focus owner and returns focus to it
via sending WM_SETFOCUS (::SetFocus(HWND) is called). This actually breaks
the mechanism AWT uses to restore focus on the most recent focus owner.
This mechanism is based on that the window should be activated at first,
i.e. it has to receive WM_ACTIVATE message. After that, on Java level,
AWT requests focus on the most recent focus owner when it handles
WINDOW_GAINED_FOCUS Java event.
However in the case being discussed EmbeddedFrame doesn't get activated,
instead, as I said, native component gets WM_SETFOCUS event. In case of
pure AWT app, KeyboardFocusManager manages this correctly in some way.
But Swing component is lightweight and it's heavyweight container which
receives WM_SETFOCUS from native system. That's why the panel, but not the
JTextField gets focus in the testcase.
I'm requesting AWT help with this. Here's what I've discovered:
When the first ALT is hit, focus is lost from the JTextField and sent to the menu item in the browser. The second ALT returns focus to the applet. However, focus goes to the Applet component itself and is not restored to the JTextField that has focus.
This same problem does not happen if the JTextField is replaced with an AWT text field. It seems that focus is automatically returned to any AWT component, but not Swing component. I expect that there is something in the AWT focus system that is working favorably for AWT components but not properly for Swing. I'm hoping AWT has an idea what this is.