如何在LWUIT中右对齐TextArea的内容?
我想将 TextArea
中的文本向右对齐。我尝试了以下代码:
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(RIGHT);
form.addComponent(textArea);
结果只是将滚动条向左移动,
但文本仍然没有对齐RIGHT
,
检查下图:
那么如何将内容与 RIGHT
对齐?
I want to align the text in a TextArea
to the right. I tried the following code:
Form form = new Form();
TextArea textArea = new TextArea("Some Arabic text ...");
textArea.setRTL(true);
textArea.setAlignment(RIGHT);
form.addComponent(textArea);
The result was just moving the scroll to left,
But the text is still not aligned RIGHT
,
check the image below:
So how to align the content to the RIGHT
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于第一个实例来说,这可能听起来很疯狂:)但是将对齐设置为
TextArea.LEFT
解决了问题,现在它是RIGHT
对齐!将其设置为
LEFT
会使显示的文本RIGHT
对齐!或者通过删除镜像显示的
textArea.setRTL(true)
对于那些对更复杂的细节感兴趣的人 > 当设置为 RTL 时:
TextArea
类的paint
方法是DefaultLookAndFeel
中的drawTextArea
方法如下:不幸的是,
TextArea. RIGHT
值为 3但是当调用
ta.getAbsoluteAlignment()
时,它会返回 1(尽管对象的对齐方式通过代码设置为TextArea.RIGHT
!!)同时
TextArea.Left
值为 1这就是为什么它匹配开关中的值并与
RIGHT
对齐顺便说一句,如果设置
它也会出错,因为
Component.RIGHT
在绘制方法之外值为 3 而不是 1!It may sound crazy for the first instance :) but setting the alignment to
TextArea.LEFT
solved the issue and now it'sRIGHT
aligned !Setting it to
LEFT
makes the displayed textRIGHT
aligned !Or by removing the
textArea.setRTL(true)
which is mirroring the displayFor those who are interested in more complicated details when it's set to RTL:
the
paint
method ofTextArea
class isAnd
drawTextArea
method inDefaultLookAndFeel
is as follows:Unfortunately
TextArea.RIGHT
value is 3But when calling
ta.getAbsoluteAlignment()
it returns 1 (despite that the object's alignment is set by code toTextArea.RIGHT
!!)Meanwhile
TextArea.Left
value is 1That's why it matched the value in the switch and was aligned to
RIGHT
BTW, if you set
it will also be wrong, because
Component.RIGHT
outside the paint method has the value 3 not 1 !您只需编写“TextArea.RIGHT”而不是“RIGHT”
You only have to write 'TextArea.RIGHT' instead of 'RIGHT'
您可以使用以下行:
You can use the following line: