United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6374321 : Textfield loses focus after alt key hit in IE browser

Details
Type:
Bug
Submit Date:
2006-01-19
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2006-04-15
Component:
client-libs
OS:
windows_2000
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Backport:
Relates:
Relates:
Relates:

Sub Tasks

Description
Text field loses focus (caret doesn't blink) when alt key is hit (twice) in the following applet :

http://rain.ireland/~sc87771/6332100/orig/sc.html

When using a pure awt version of this applet this problem is not seen :
http://rain.ireland/~sc87771/6332100/ms/sc.html

Seen on mantis,tiger and mustang.
Hitting the tab key will restore the focus in the swing version.
CR 6332100 is similar but involves using alt-tab and is reproducible in pure awt version.

                                    

Comments
EVALUATION

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.
                                     
2006-02-10
EVALUATION

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.
                                     
2006-02-22
EVALUATION

It has appeared the some time back we already resolved some problem that was
symmetric to this one. That is when a component inside an applet loses focus
we send synthetic WM_ACTIVATE(WA_INACTIVE) to deactivate the EmbeddedFrame.
So, the same should be done when a component gets focus from outside whereas the
EmbeddedFrame is not active. We have to send it WM_ACTIVATE(WA_ACTIVE) to activate
it synthetically.

I'll come up with diffs some time later. The point is that the diffs depend on the fix
for 2134972 that is being reviewed so far.
                                     
2006-03-03
SUGGESTED FIX

See the webrev here: http://javaweb.sfbay/jcg/1.6.0-mustang/awt/6374321
                                     
2006-04-04



Hardware and Software, Engineered to Work Together