【发布时间】:2011-09-22 10:49:00
【问题描述】:
我有JScrollPane,里面有JTextArea,我试图将JTextArea的方向设置为从右到左,这样它里面的文本将从右边开始,滚动条在左边
我尝试了以下方法,但它们不影响方向的方向:
txt.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txt.setAlignmentX(JTextArea.RIGHT_ALIGNMENT);
编辑:
camickr 和trashgod 提供的两个答案工作正常,但在我使用JTextArea 作为对象消息并将其传递给OptionPane 的程序中却不行。
EDIT2:
我发现如果我将 setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 应用到 JOptionPane 内容上,它就不起作用.. 这个问题有替代解决方案吗?
类似于我的代码:
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class TextArea extends JPanel
{
private JTextArea txt = new JTextArea();
public TextArea()
{
setLayout(new GridLayout());
txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
JScrollPane scroll = new JScrollPane(txt);
scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
setPreferredSize(new Dimension(200,200));
this.add(scroll);
}
private void display()
{
Object[] options = {this};
JOptionPane pane = new JOptionPane();
int option = pane.showOptionDialog(null, null, "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
}
public static void main(String[] args)
{
new TextArea().display();
}
}
【问题讨论】:
-
最后,一个SSCCE,应该随每个问题发布。查看我的更新。
标签: java swing arabic jtextarea