这听起来很疯狂一审:)但对齐设置为TextArea.LEFT
解决问题“TextArea.RIGHT”,现在是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);
}
而在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
这就是为什么它匹配t他在开关量,并对准RIGHT
顺便说一句,如果你设置
textArea.setAlignment(Component.RIGHT);
这也将是错误的,因为Component.RIGHT
paint方法外面的值是3而不是1!
当您为'TextArea'激活** RTL **时,文本渲染的方向将反转,因此Left被视为正确。我建议你通过填写@ [LWUIT Java表单](http://www.java.net/forums/mobile-embedded/lwuit)来从Shai得到澄清。从而为LWUIT社区做出贡献。 – Vimal
Vimal是正确的。这听起来很奇怪,但一旦你想到它就很有意义。当你激活bidi时,你有效地倒转了显示器,所以右边是左边,东边是西边...这对于RTL应用程序来说是有意义的,因为在这些应用程序中,99%的UI组件要与英文版完全相反,因此您可以编写英文用户界面,并通过翻译和翻转双向交换机将其本地化为bidi。 –
是的,它可以通过删除我的初始文章中的这一行代码来完成:** textArea.setRTL(true); **和保持原样。感谢这宝贵的意见! –