Blackberry Java:TextField *没有*插入符号?

发布于 2024-08-04 12:37:59 字数 74 浏览 6 评论 0原文

我想要一个不可编辑的 TextField (或子类),它甚至没有显示插入符号。或者,我想要一个多行 LabelField。这些可能吗?

I want a non-editable TextField (or a subclass) that doesn't even have the caret displayed. Alternatively, I want a multiline LabelField. Is any of these possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

心如荒岛 2024-08-11 12:37:59

没有焦点光标的 TextField

TextField readOnly = new TextField(NON_FOCUSABLE);
readOnly.setText("Read only, no carret");
add(readOnly);

TextField drawFocus 重写

如果文本太大而无法适应屏幕,您可以重写 TextField 中的 drawFocus 方法,这样就可以滚动:

TextField readOnly = new TextField(READONLY)
{
    protected void drawFocus(Graphics graphics, boolean on) {}
};

TextFields,用 NullFields 分隔

其他选项是将 TextField 拆分为多个,用 NullFields 分隔:

class Scr extends MainScreen {
    public Scr() {

        String text = "Lorem ipsum dolor sit amet, consectetuer "
                + "adipiscing elit, sed diam nonummy nibh euismod "
                + "tincidunt ut laoreet dolore magna aliquam erat "
                + "volutpat. Ut wisi enim ad minim veniam, quis "
                + "nostrud exerci tation ullamcorper suscipit "
                + "lobortis nisl ut aliquip ex ea commodo consequat. "
                + "Duis autem vel eum iriure dolor in hendrerit in "
                + "vulputate velit esse molestie consequat, vel "
                + "illum dolore eu feugiat nulla facilisis at vero "
                + "eros et accumsan et iusto odio dignissim qui "
                + "blandit praesent luptatum zzril delenit augue "
                + "duis dolore te feugait nulla facilisi.";

        text = addScrollText(text, 150);
    }

    private String addScrollText(String text, int partSize) {
        while (0 < text.length()) {
            int len = Math.min(partSize, text.length());
            TextField readOnly = new TextField(NON_FOCUSABLE);
            readOnly.setText(text.substring(0, len));
            add(readOnly);
            add(new NullField());
            text = text.substring(len);
        }
        return text;
    }
}

多行LabelField

LabelField 中的多行文本,只需使用换行转义字符:

String text = "first line \nnew line \nanother line";
LabelField multiLine = new LabelField(text);
add(multiLine);

TextField without focus cursor

TextField readOnly = new TextField(NON_FOCUSABLE);
readOnly.setText("Read only, no carret");
add(readOnly);

TextField drawFocus override

If text is too large to fit the screen, you can override drawFocus method in TextField, so scrolling will be available:

TextField readOnly = new TextField(READONLY)
{
    protected void drawFocus(Graphics graphics, boolean on) {}
};

TextFields, separated with NullFields

Other option is to split TextField into several, separated with NullFields:

class Scr extends MainScreen {
    public Scr() {

        String text = "Lorem ipsum dolor sit amet, consectetuer "
                + "adipiscing elit, sed diam nonummy nibh euismod "
                + "tincidunt ut laoreet dolore magna aliquam erat "
                + "volutpat. Ut wisi enim ad minim veniam, quis "
                + "nostrud exerci tation ullamcorper suscipit "
                + "lobortis nisl ut aliquip ex ea commodo consequat. "
                + "Duis autem vel eum iriure dolor in hendrerit in "
                + "vulputate velit esse molestie consequat, vel "
                + "illum dolore eu feugiat nulla facilisis at vero "
                + "eros et accumsan et iusto odio dignissim qui "
                + "blandit praesent luptatum zzril delenit augue "
                + "duis dolore te feugait nulla facilisi.";

        text = addScrollText(text, 150);
    }

    private String addScrollText(String text, int partSize) {
        while (0 < text.length()) {
            int len = Math.min(partSize, text.length());
            TextField readOnly = new TextField(NON_FOCUSABLE);
            readOnly.setText(text.substring(0, len));
            add(readOnly);
            add(new NullField());
            text = text.substring(len);
        }
        return text;
    }
}

Multiline LabelField

Multiline text in LabelField, just use newline escape character:

String text = "first line \nnew line \nanother line";
LabelField multiLine = new LabelField(text);
add(multiLine);
腻橙味 2024-08-11 12:37:59

是的,你可以重写每个UI元素的paint方法

一个例子:

public class WhiteLabelField extends LabelField 
{
    public WhiteLabelField()
    {
        super();
    }
    public WhiteLabelField(ObjectGroup text)
    {
        super(text);
    }
    public WhiteLabelField(Object text, long style)
    {
        super(text, style);
    }
    public void paint(Graphics _g)
    {
        _g.setColor(Color.WHITE);
        super.paint(_g);
    }
    // Custom
    public void setSmallFontSize()
    {
        setFont( Font.getDefault( ).derive( Font.PLAIN, 16 ));
    }
}

Yes, you can override the paint method of each UI Element

An example:

public class WhiteLabelField extends LabelField 
{
    public WhiteLabelField()
    {
        super();
    }
    public WhiteLabelField(ObjectGroup text)
    {
        super(text);
    }
    public WhiteLabelField(Object text, long style)
    {
        super(text, style);
    }
    public void paint(Graphics _g)
    {
        _g.setColor(Color.WHITE);
        super.paint(_g);
    }
    // Custom
    public void setSmallFontSize()
    {
        setFont( Font.getDefault( ).derive( Font.PLAIN, 16 ));
    }
}
小鸟爱天空丶 2024-08-11 12:37:59

您还可以使用具有 Field.NON_FOCUSABLE 样式的 RichTextField,您将获得所需的内容。

You could also use a RichTextField with a style of Field.NON_FOCUSABLE and you will have what you want.

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