How to set the orientation of JTextArea from right to left (inside JOptionPane)

后端 未结 4 445
孤城傲影
孤城傲影 2020-11-27 22:54

I have JScrollPane with JTextArea inside it and I am trying to set the JTextArea\'s orientation from right to left so the text inside it will start

4条回答
  •  粉色の甜心
    2020-11-27 23:20

    The following lines solved my problem:

    jTextArea1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    jTextArea1.setText();
    

    They serve to:

    1. setComponentOrientation() changes the orientation of the TextArea; and,
    2. setText() refreshes TextArea immediately so it displays properly

    Simply setting ComponentOrientation to RIGHT_TO_LEFT is not sufficient by itself. repaint() doesn't force the text to realign itself. A quick solution for me was to update the contents of the TextArea. That forced the text to realign itself.

提交回复
热议问题