I it possible to align the text inside a JTextArea to the right (or change the text alignment in general)?
|Left |
| Centered |
| Right|
I've been searching for hours and it seems others have asked this question before but there are no good answers (that actually work).
Thanks in advance!
解决方案
Try with JEditorPane or JTextPane instead of JTextArea.
Please have a look at my another post JEditorPane vertical aligment for complete sample code.
Sample code:
JTextPane output = new JTextPane();
SimpleAttributeSet attribs = new SimpleAttributeSet();
StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT);
output.setParagraphAttributes(attribs, true);
EDIT
You can try
JTextArea jTextArea = new JTextArea();
jTextArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);