对于第一个实例来说这听起来很疯狂 :) 但是将对齐设置为 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 时更复杂的细节感兴趣的人:
TextArea 类的 paint 方法是
public void paint(Graphics g) {
UIManager.getInstance().getLookAndFeel().drawTextArea(g, this);
}
而DefaultLookAndFeel中的drawTextArea方法如下:
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.RIGHT 的值为 3
但是当调用ta.getAbsoluteAlignment() 时它返回1(尽管对象的对齐方式是由代码设置为TextArea.RIGHT !!)
同时TextArea.Left值为1
这就是它与开关中的值匹配并与RIGHT对齐的原因
顺便说一句,如果你设置了
textArea.setAlignment(Component.RIGHT);
也会出错,因为paint方法外的Component.RIGHT的值是3而不是1!