JDK-6473485 : No keyboard focus in a focusable JWindow
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-09-21
  • Updated: 2014-02-27
  • Resolved: 2007-01-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0u12 b01Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Keyboard focus is not transfered to JWindows with JFrame owners altough the JWindow is focusable.

This is working properly under 1.4.2_12 , 1.5.0_6, 1.5.0_7.  broken only in 1.5.0_8
Maybe a side effect of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6399303 ?

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program. Partially cover the JWindow with some other process's window and make sure this other window has keyboard focus. Now, use the mouse to click and select the text in the JWindow's text field.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
when the text field is clicked , the other window should be minimized, text field should gain keyboard focus
ACTUAL -
Text field does not gain keyboard  focus . Other external window is not minimized

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
public class FocusTest {
  public static final void main(String[] args){
        JFrame mainFrame = new JFrame("Main frame");
        mainFrame.getContentPane().add(new JLabel("Main frame label"));
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.pack();
        JWindow sonWindow = new JWindow(mainFrame);
        sonWindow.getContentPane().add(new JLabel("Child Window label"));
        sonWindow.getContentPane().add(new JTextField("Child Window Field"));
        sonWindow.pack();
        sonWindow.show();
        mainFrame.show();
        System.out.println("Son window is focusable: "+sonWindow.isFocusable());
        System.out.println("Son window focusable state: "+sonWindow.getFocusableWindowState());

        //sonWindow.setFocusableWindowState(true); //uncommenting this line workaround the bug
  }

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Calling sonWindow.setFocusableWindowState(true);  after the window is shown fixes it. Note that the jwindow is focusable at this time!

This workaround is not good for our application since we don't create the JWindows they are created by a third party framework.

Release Regression From : 5.0u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
SUGGESTED FIX The webrev: http://javaweb.sfbay/jcg/5.0u12/awt/6473485
23-01-2007

EVALUATION One more regression of the original backport that should also be fixed: 6469440 "Regression: Encounter NPE when trying to print a help topic provided by JavaHelp".
17-11-2006

EVALUATION This is a regression of the fix for 6399303, integrated into 5.0u8 b01. This fix is a partial backport of the fixes integrated into mustang: 6181725, 5091224, 6384552. However that fixes do not completely resolve the problem with focusability of a window. If an owned window is shown before its owner then its focusability should be updated while showing the owner. This is addressed in mustang by these fixes: 6253913, 6391763. So, we also have to backport these two fixes from mustang.
03-11-2006

EVALUATION .
02-10-2006

EVALUATION The bug is not reproducible with 6.0, however, I haven't found any differences in handling focusableWindowState between 6.0 and 5.0u8. I have also found that in 5.0u8 the window has WS_EX_NOACTIVATE style, and this leads to the wrong behaviour.
25-09-2006