JDK-4701238 : REGRESSION: Bidirectional text not working in JTextComponents
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0,1.4.0,5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: generic,solaris_7,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2002-06-12
  • Updated: 2014-02-12
  • Resolved: 2014-02-12
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
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) 
======================================================================

Comments
WORK AROUND Developer can explicitly set component orientation component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); ###@###.### 2005-09-08
08-09-2005

WORK AROUND Press Ctrl+Shift+'O' to switch the base line direction in the text component, which will go back to the 1.3.1 behavior in this case. (2005-08-12)
11-08-2005

EVALUATION Committed to Mantis. ###@###.### 2002-06-18 The reason of this problem is that as a result of the fix for the bug 4300552, the default base run direction is inherited from the component orientation in the Swing text components. In this problem case, this is LeftToRight, which seems reasonable to me as component is LTR aligned. Maybe it needs to be more flexible that users can override the default behavior. Re-committing to Tiger. ###@###.### 2002-11-12
12-11-2002