如何在lwuit(J2ME)中显示多行文本区域?
我创建了一个带有语句的 TextArea
....
quest1Label = new TextArea();
我使用 TextArea
来显示 Labels
...所以我使用以下函数设置其属性...
private void setTextAreaProperty(TextArea textArea) {
String textStr = textArea.getText();
if (textArea.getStyle().getFont().stringWidth(textStr) > (width - 25)) {
textArea.setSingleLineTextArea(false);
} else {
textArea.setSingleLineTextArea(true);
textArea.setPreferredW(width);
}
textArea.setBorderPainted(false);
textArea.setFocusable(false);
textArea.setStyle(getPreviewStyle());
}
其中 width = Display.getInstance().getDisplayWidth(); 我的问题是,最多两行标签可以正常工作,但是......如果文本更大,它不会转到第三行。 任何有关这方面的帮助将不胜感激。
提前致谢,....
I have created a TextArea
with statement ....
quest1Label = new TextArea();
I am using the TextArea
for displaying the Labels
.... So I use following function to set its properties....
private void setTextAreaProperty(TextArea textArea) {
String textStr = textArea.getText();
if (textArea.getStyle().getFont().stringWidth(textStr) > (width - 25)) {
textArea.setSingleLineTextArea(false);
} else {
textArea.setSingleLineTextArea(true);
textArea.setPreferredW(width);
}
textArea.setBorderPainted(false);
textArea.setFocusable(false);
textArea.setStyle(getPreviewStyle());
}
where width = Display.getInstance().getDisplayWidth();
my problem is that up to two lines the label works properly but .... if the text is even larger it doesn't go to third line.
any help regarding this will be appreciated.
Thanks in Advance,....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用像
new TextArea(1, 20)
这样的TextArea
构造函数,它允许布局更有效地“增长”。原因主要是历史性的,LWUIT 对于
TexAarea
默认为 3 列,这允许TexAarea
很好地收缩,但在增长时很糟糕。增长/收缩的复杂性源于布局可以深度嵌套和可滚动的事实,因此可用空间与所需空间的计算变得递归,并且在某些难以检测的点无法解决(无限递归)。You need to use the
TextArea
constructor like thisnew TextArea(1, 20)
which allows the layout to "grow" more effectively.The reason is mostly historic, LWUIT had a 3 column default for
TexAarea
which allow theTexAarea
to shrink well but sucks when growing. The complexity in growing/shrinking is derived by the fact that layouts can be deeply nested and scrollable hence the available space vs. desired space calculation becomes recursive and at some hard to detect point unsolvable (infinite recursion).您是否尝试过 setGrowByContent ?也许默认的行数是 2,并且它不会增长超过这个数。
问候。
Have you tried setGrowByContent? Maybe the default number of rows is 2, and it doesn't grow more than that.
Regards.