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

JTextField's size is computed incorrectly when it contains Indic or Thai characters

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 6, 7, 8, 9, 10, 11, 12, 13
    • Fix Version/s: tbd
    • Component/s: client-libs
    • Subcomponent:
    • Introduced In Version:
      6
    • Resolved In Build:
      b68
    • CPU:
      generic
    • OS:
      linux

      Description

      SYNOPSIS
      --------
      JTextField's size is computed incorrectly when it contains Indic or Thai characters

      OPERATING SYSTEMS
      -----------------
      All (tested on Windows and Linux)

      FULL JDK VERSION
      ----------------
      All, including JDK 8

      PROBLEM DESCRIPTION from LICENSEE
      -------------------
      When a JTextField contains an Indic or Thai character, the size (especially height) of the JTextField is calculated incorrectly such that the text in the JTextField is not properly visible. In our testcase the size is calculated as 4 when it should be 19.

      Our analysis so far has revealed that the issue doesn't happen with Chinese/Japanese characters. For the characters in the testcase, the view for rendering is 'I18nFieldView', and the preferredSpan along the Y-Axis is calculated to be 0. For chinese/Japanese glyphs, the view for rendering is 'FieldView', and the size is calculated correctly.

      It seems that the issue occurs with any character that Swing renders with i18n views.

      REPRODUCTION INSTRUCTIONS
      -------------------------
      1. Compile and run the attached testcase.

      Expected behaviour:
      Two text fields should be visible, with a suitable height to display the text they contain.

      Actual Behaviour:
      The two text fields are present, but the height is not suitable fot the text they contain cannot be seen (the text is unreadable).

      WORKAROUND
      ----------
      Make an explicit call to getPreferredSize() on the JTextField instance. The effect of this call can be seen by un-commenting line 13 of the testcase.

      TESTCASE
      --------
      import java.awt.*;
      import javax.swing.*;

      public class TextFieldTest {
          public static void main(String[] args) {
              JFrame frame = new JFrame("JTextField Test");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              JPanel container = (JPanel) frame.getContentPane();
              container.setLayout(new GridLayout(2, 1));

              JTextField textField = new JTextField("\u0e01"); //Thai
              //System.out.println(textField.getPreferredSize()); // uncommenting this line makes the rendering correct
              JTextField textField1 = new JTextField("\u0c01"); //Telugu

              container.add(textField);
              container.add(textField1);
              frame.setVisible(true);
              frame.pack();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                psadhukhan Prasanta Sadhukhan
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: