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

REGRESSION: Bidirectional text not working in JTextComponents

    XMLWordPrintable

Details

    • generic, x86, sparc
    • generic, solaris_7, windows_nt

    Backports

      Description

        Name: gm110360 Date: 06/12/2002


        FULL PRODUCT VERSION :
        java version "1.4.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
        Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

        Also in 1.4.0_01

        FULL OPERATING SYSTEM VERSION : Windows NT Version 4.0 sp 6


        A DESCRIPTION OF THE PROBLEM :
        Bidirectional text is not displayed correctly (or input
        correctly if using an arabic machine) in JTextComponents
        (JTextArea and JTextField - others untested).

        Specifically the base direction of the text always seems to
        be left to right. If the logical text starts with arabic
        characters, and then english characters, when its displayed
        on screen the arabic should be on the right (as this should
        be treated as primarily arabic text with embedded english,
        so reading would start from the right)

        The text is displayed correctly in JLabel and JTable, but
        incorrectly in JTextfield and JTextArea (where the arabic
        is on the left)

        When entering text (on arabic NT), the same problem occurs.
        If the user types english then arabic then english the
        results are correct as in this case the base direction is
        left to right.

        However if arabic is entered first, then english the
        english text appears on the right instead of on the left as
        expected where the base direction is right to left.

        Despite this the text enetered is stored correctly (as can
        be seen by copying to a JLabel)

        REGRESSION. Last worked in version 1.3.1

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Create a String with arabic characters first, then
        english eg 'ABC abc' where the capitals denote arabic
        (An actual string could be "\u0634\u0627\u062f\u062c
        english")
        2. Set this text on a JTextField and a JLabel
        3. The displayed text will be different, on the JTextField
        the arabic will incorrectly appear to the left.
        4. To reproduce the entering text problem, use an arabic
        enabled machine and enter some arabic, then switch to
        english, the english will start to appear on the right
        instead of the left.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        The expected results would be 'abc CBA' since arabic reads
        backwards, and the english is embedded in it.

        The actual results are correct on the JLabel, but 'CBA abc'
        on the JTextField

        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;

        public class Frame1 extends JFrame
        {
            JLabel label = new JLabel();
            JTextField textfield = new JTextField();
            JTextArea textarea = new JTextArea();
            JButton button = new JButton("copy textfield to label");

            public Frame1()
            {
            // Font settings not needed in 1.4 - its done automatically
            // Font arabicFont = new Font("Tahoma", 0, 12);
            // label.setFont(arabicFont);
            // textfield.setFont(arabicFont);
            // textarea.setFont(arabicFont);

                textarea.setEditable(false);

        // Pressing the button demonstrates that any entered text is stored correctly
        // even though its displayed incorrectly

                button.addActionListener(new ActionListener()
                {
                    public void actionPerformed(ActionEvent e)
                    {
                        label.setText(textfield.getText());
                    }
                });

                String text = "\u0634\u0627\u062f\u062c english";

                textfield.setText(text);
                textarea.setText(text);
                label.setText(text);

                setSize(new Dimension(600, 300));
                getContentPane().setLayout(new GridLayout(2,2));
                getContentPane().add(label);
                getContentPane().add(textfield);
                getContentPane().add(button);
                getContentPane().add(textarea);

                setVisible(true);
            }

            public static void main(String[] args)
            {
                new Frame1();
            }
        }
        ---------- END SOURCE ----------

        Release Regression From : 1.3.1
        The above release value was the last known release where this
        bug was known to work. Since then there has been a regression.

        (Review ID: 153472)
        ======================================================================

        Attachments

          Issue Links

            Activity

              People

                Unassigned Unassigned
                gmanwanisunw Girish Manwani (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: