[英]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.