1
我与ComponentOrientation.RIGHT_TO_LEFT
的问题是,诸如'/'或'!'之类的字符要么 '。'显示在左侧。文本区域右侧的Java显示文本
我只需要从右向左绘制文本,但使用标准,西方,英文左到右的符号表示文本字符。
这可能没有手动呈现文本?
我与ComponentOrientation.RIGHT_TO_LEFT
的问题是,诸如'/'或'!'之类的字符要么 '。'显示在左侧。文本区域右侧的Java显示文本
我只需要从右向左绘制文本,但使用标准,西方,英文左到右的符号表示文本字符。
这可能没有手动呈现文本?
我不能生成你的问题,请你用我的SSCCE来显示在左边。
从代码
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)
文本字段。
OP希望像''one /''这样的文本显示为右对齐,但是按照从左到右的顺序排列。 – 2012-03-11 22:03:53
我得到它使用JTextField.setHorizontalAlignment(JTextField.RIGHT) – bgroenks 2012-03-12 00:58:08