我可以将JTextArea中的文本向右对齐(或通常更改文本对齐方式)吗?
|Left | | Centered | | Right| <- Like this
我一直在搜索数小时,似乎其他人之前也曾问过这个问题,但没有好的答案(这确实有效)。
提前致谢!
尝试使用JEditorPane或JTextPane代替JTextArea。
JEditorPane
JTextPane
JTextArea
有关更多信息,请查看此线程在JEditorPane中的文本垂直对齐
样例代码:
JTextPane output = new JTextPane(); SimpleAttributeSet attribs = new SimpleAttributeSet(); StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT); output.setParagraphAttributes(attribs, true);
你可以试试
JTextArea jTextArea = new JTextArea(); jTextArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);