在键入之前:
JTextArea textArea = new JTextArea();
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
JScrollPane scroll = new JScrollPane(textArea);
scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
import java.awt.ComponentOrientation;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Test extends JFrame {
public Test() {
this.setSize(300, 100);
JTextArea textArea = new JTextArea();
textArea.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
JScrollPane scroll = new JScrollPane(textArea);
scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
this.add(scroll);
this.setVisible(true);
}
}
我在Windows 10上使用Java 11fy.
这似乎对我有用(在Mac上进行了测试)。
有点骇客,但正如您所说的。没有写任何东西,caret是默认为左侧的。