我JScrollPane跟JTextArea里面,我试图从右侧设置的JTextArea的方向向左所以里面的文字就会从右边开始,滚动条会出现在左边
我尝试过以下但是它们并没有影响方向的方向:
txt.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txt.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
txt.setAlignmentX(JTextArea.RIGHT_ALIGNMENT);
Run Code Online (Sandbox Code Playgroud)
编辑:
两个答案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) …Run Code Online (Sandbox Code Playgroud)