第一次听起来可能很疯狂:)但是设置对齐来TextArea.LEFT解决问题,现在它已经RIGHT对齐了!
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(TextArea.LEFT);
form.addComponent(textArea);
将其设置为LEFT使显示的文本RIGHT对齐!
或者通过删除textArea.setRTL(true)镜像显示的
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setAlignment(TextArea.RIGHT);
form.addComponent(textArea);
对于那些对设置为 RTL 时更复杂的细节
感兴趣的人:类
的paint方法TextArea是
public void paint(Graphics g) {
UIManager.getInstance().getLookAndFeel().drawTextArea(g, this);
}
drawTextArea方法DefaultLookAndFeel如下:
int align = ta.getAbsoluteAlignment();
// remaining code is here in initial source
switch(align) {
case Component.RIGHT:
x = ta.getX() + ta.getWidth() - rightPadding - f.stringWidth(displayText);
break;
// remaining code is here in initial source
}
g.drawString(displayText, x, y);
不幸的是TextArea.RIGHTvalue 是 3
但是当调用ta.getAbsoluteAlignment()它时返回 1 (尽管对象的对齐方式是由代码设置为TextArea.RIGHT!!)
同时TextArea.Leftvalue 是 1
这就是为什么它匹配 switch 中的值并对齐到RIGHT
顺便说一句,如果你设置
textArea.setAlignment(Component.RIGHT);
它也将是错误的,因为Component.RIGHT在 paint 方法之外的值是 3 而不是 1 !