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

IME does not work properly in some cases (Chinese keyboard - zh_CN)

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_101"
      Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
      Java HotSpot(TM) Client VM (build 25.101-b13, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Keyboards installed via Windows "Region and Language" settings:
      English : Keyboard : US
      Chinese (Simplified, PRC) : Keyboard : Chinese (Simplified) - Microsoft Pinyin New Experience Input Style
      Chinese (Traditional, Taiwan) : Keyboard : Chinese (Traditional) - New Phonetic

      A DESCRIPTION OF THE PROBLEM :
      Attempting to change the Input Method from "Chinese (Simplified)" to "English" via getInputContext().selectInputMethod(Locale.US) results in the Input Method being instead set to "Chinese (Traditional)" when you have both Chinese keyboards enabled in Windows.

      Changing from Chinese Traditional to English functions as expected.
      Changing form Chinese Simplified to Chinese Traditional functions as expected.

      Installing additional language keyboards on the system makes the problem worse and causes other keyboards to be selected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open the Region and Language settings in Windows Control Panel.
      Select the "Keyboards and Languages" tab
      Click "Change keyboards..."
      Click "Add..."
      Select the Checkbox for "Chinese (Simplified, PRC) -> Keyboard -> Chinese (Simplified) - Microsoft Pinyin New Experience Input Style
      Select the Checkbox for "Chinese (Traditional, Taiwan) -> Keyboard -> Chinese (Traditional) - New Phonetic
      Press Ok.

      Run the attached Example code.

      Change the dropdown from "en_US" to "zh_TW" and observe the correct behavior.
      Change the dropdown from "zh_TW" to "en_US" and observe the correct behavior.
      Change the dropdown from "en_US" to "zh_CN" and observe the correct behavior.
      Change the dropdown from "zh_CN" to "en_US" and observe that the IM is now somehow set to Chinese Traditional instead of English.
      Open dropdown and re-select "en_US" and observe that language is now properly "en_US" (usually)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected language to always change to "en_US" when selecting "en_US" from the dropdown.
      ACTUAL -
      When changing from "zh_CN" the language instead becomes "zh_TW"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.util.ArrayList;
      import java.util.List;
      import java.util.Locale;


      public class IMETest extends JPanel implements ActionListener {

          JComboBox comboBox;

          public IMETest() {

              setLayout(new BorderLayout());

              final List<Locale> locales = new ArrayList<Locale>();
              locales.add(Locale.US);
              locales.add(Locale.SIMPLIFIED_CHINESE);
              locales.add(Locale.TRADITIONAL_CHINESE);
              comboBox = new JComboBox(locales.toArray());
              add(comboBox, BorderLayout.NORTH);
              comboBox.addActionListener(this);

              final JTextArea textArea = new JTextArea();
              add(textArea, BorderLayout.CENTER);
          }

          private static void createAndShowGUI() throws UnsupportedLookAndFeelException {

              JFrame frame = new JFrame("ComboBox IME Example");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              IMETest newContentPane = new IMETest();
              newContentPane.setOpaque(true);
              frame.setContentPane(newContentPane);

              //Display the window.
              frame.setSize(300, 300);
              frame.setVisible(true);
              frame.setLocationRelativeTo(null);
          }

          public static void main(String[] args) {
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      try {
                          createAndShowGUI();
                      } catch (UnsupportedLookAndFeelException e) {
                          e.printStackTrace();
                      }
                  }
              });
          }

          @Override
          public void actionPerformed(ActionEvent e) {
              Locale selectedLocale = (Locale)comboBox.getSelectedItem();
              getInputContext().selectInputMethod(selectedLocale);
              Locale actualLocale = getInputContext().getLocale();
              System.out.println("Attempted to set Input Context to locale: " + selectedLocale + " and got " + actualLocale);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Sometimes attempting to set the language again succeeds - sometimes it does not.

      Problem seems to be exacerbated by installing even more language keyboards

            naoto Naoto Sato
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: