简体   繁体   中英

Java Display Text On Right Side of Text Area

The problem I have with ComponentOrientation.RIGHT_TO_LEFT is that characters such as '/' or '!' or '.' are shown on the left side.

I just need text to be drawn from right to left but using standard, western, English left to right notation for text characters.

Is this possible without manually rendering text?

I can't generating your issue, can you please use my SSCCE for shown on the left side.

在此输入图像描述

from code

import java.awt.ComponentOrientation;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;

public class RightToLeft {

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                JTextArea text = new JTextArea(10, 5);
                text.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                text.setText("one/\n "
                        + "!two\n"
                        + ".three\n"
                        + "/four\n"
                        + "five!\n"
                        + "six.\n"
                        + "seven\n"
                        + "eight\n");
                JScrollPane pane = new JScrollPane(text);
                JFrame.setDefaultLookAndFeelDecorated(true);
                JFrame frame = new JFrame("العنوان بالعربي");
                frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
                frame.add(pane);
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.setVisible(true);
            }
        });
    }
}

尝试为文本字段调用setAlignmentX(Component.RIGHT_ALIGNMENT)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM