JDK-8187635 : On Windows Swing changes keyboard layout on a window activation
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u144,10,11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-09-18
  • Updated: 2024-01-23
  • Resolved: 2018-02-28
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.
JDK 11 JDK 8 Other
11 b05Fixed 8u162Fixed openjdk7uFixed
Related Reports
Relates :  
Description
On Windows Swing changes keyboard layout on a window activation 

If "Let me set a different input method for each app window" checkbox is disabled, Swing applications switch System keyboard layout to the layout they were started with. 

On Windows 10 you can find the checkbox at Control Panel -> Clock, Language and Region -> Language -> Advanced Settings -> "Let me set a different input method for each app window" 

To reproduce the problem, disable the checkbox. 

Add at least two languages at Control Panel -> Clock, Language and Region -> Language -> Change you language preferences 
For instance, you can add Russian and English languages 

Run the java app 

public class Test { 
    public static void main(String[] args) { 
        SwingUtilities.invokeLater(() -> { 
            JFrame jFrame = new JFrame("Test"); 
           
            jFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
            jFrame.setSize(new Dimension(200,200)); 
            jFrame.add(new JTextArea()); 
            jFrame.pack(); 
            jFrame.setVisible(true); 
        }); 
    } 
} 

Deactivate the Swing frame (click on the desktop or any other application window), change the input language. 

Activate the Swing frame again. Being activated the frame changes the input language system wide. 
Comments
URL: http://hg.openjdk.java.net/jdk/jdk/rev/838c11e59a38 User: prr Date: 2018-03-13 18:12:30 +0000
13-03-2018

URL: http://hg.openjdk.java.net/jdk/client/rev/838c11e59a38 User: dmarkov Date: 2018-02-28 22:05:50 +0000
28-02-2018

The problem is reproducible on 8u162, 10 and 11.
21-02-2018

Problem description: On Windows platform if AWT/Swing app is inactive (does not have focus) and user changes keyboard layout, the app window will receive the message WM_INPUTLANGCHANGE upon activation. During message processing we do NOT set the following flag g_bUserHasChangedInputLang. So the keyboard layout is switched back by AWT toolkit via WM_AWT_ACTIVATEKEYBOARDLAYOUT event. Fix: It is necessary to set the flag g_bUserHasChangedInputLang during processing of WM_INPUTLANGCHANGE to block execution of activateKeyboardLayout() from AwtToolkit.WndProc().
21-02-2018

Does it affect 9? 10?
25-09-2017