Java在文本区域的右侧显示文本
我在组件方向上遇到的问题是,从右到左的字符是“/”或“!”或“.”显示在左侧 我只需要从右到左绘制文本,但使用标准的、西文的、英文的从左到右符号表示文本字符Java在文本区域的右侧显示文本,java,swing,text,orientation,right-to-left,Java,Swing,Text,Orientation,Right To Left,我在组件方向上遇到的问题是,从右到左的字符是“/”或“!”或“.”显示在左侧 我只需要从右到左绘制文本,但使用标准的、西文的、英文的从左到右符号表示文本字符 如果不手动渲染文本,是否可以执行此操作?我无法生成您的问题,请使用左侧显示的我的 源代码 import java.awt.ComponentOrientation; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea
如果不手动渲染文本,是否可以执行此操作?我无法生成您的问题,请使用左侧显示的我的 源代码
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\u ALIGNMENT)
。OP希望像“one/”
这样的文本显示为右对齐,但以从左到右的流程排列。我使用JTextField.setHorizontalAlignment(JTextField.RIGHT)实现了这一点