Java display text on the right side of the text area

The problem with ComponentOrientation.RIGHT_TO_LEFTis that characters like '/' or '!' or '.' shown on the left side.

I just need text that needs to be drawn from right to left, but using standard, western, english left and right notation for text characters.

Is this possible without manually rendering the text?

+1
source share
2 answers

I cannot create your problem, can you use my SSCCE for the one shown on the left.

enter image description here

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);
            }
        });
    }
}
+3
source

setAlignmentX(Component.RIGHT_ALIGNMENT) .

0

Source: https://habr.com/ru/post/1629590/


All Articles