[英]Java Display Text On Right Side of Text Area
我在ComponentOrientation.RIGHT_TO_LEFT
的问题是'/'或'!'等字符 要么 '。' 显示在左侧。
我只需要从右到左绘制文本,但使用标准,西方,英文从左到右的符号表示文本字符。
没有手动渲染文本,这可能吗?
来自代码
import java.awt.ComponentOrientation;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
public class RightToLeft {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
JTextArea text = new JTextArea(10, 5);
text.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
text.setText("one/\n "
+ "!two\n"
+ ".three\n"
+ "/four\n"
+ "five!\n"
+ "six.\n"
+ "seven\n"
+ "eight\n");
JScrollPane pane = new JScrollPane(text);
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("العنوان بالعربي");
frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.add(pane);
frame.pack();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
尝试为文本字段调用setAlignmentX(Component.RIGHT_ALIGNMENT)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.