如何在lwuit(J2ME)中显示多行文本区域?

发布于 2024-11-25 13:32:40 字数 803 浏览 0 评论 0原文

我创建了一个带有语句的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳 2024-12-02 13:32:40

您需要使用像 new TextArea(1, 20) 这样的 TextArea 构造函数,它允许布局更有效地“增长”。

原因主要是历史性的,LWUIT 对于 TexAarea 默认为 3 列,这允许 TexAarea 很好地收缩,但在增长时很糟糕。增长/收缩的复杂性源于布局可以深度嵌套和可滚动的事实,因此可用空间与所需空间的计算变得递归,并且在某些难以检测的点无法解决(无限递归)。

You need to use the TextArea constructor like this new 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 the TexAarea 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).

薔薇婲 2024-12-02 13:32:40

您是否尝试过 setGrowByContent ?也许默认的行数是 2,并且它不会增长超过这个数。

问候。

Have you tried setGrowByContent? Maybe the default number of rows is 2, and it doesn't grow more than that.

Regards.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文