OS 4.5 和 6.0 之间的 LabelField 不同行为

发布于 2025-01-03 13:16:03 字数 1366 浏览 1 评论 0 原文

在我的应用程序中,我必须实现从 VerticalFieldManager 扩展的自定义组件,并且该管理器保存 Horizo​​ntalFieldManager 的行。 问题是在 OS 4.5 中,左侧的 LabelField 仅显示一行文本。这是代码和图像。BB6.0 在此处输入图像描述

class Row extends HorizontalFieldManager{
    private LabelField key;
    private LabelField value;

    public Row(String left,String right){
        key = new LabelField(left + ": ",Field.NON_FOCUSABLE | Field.NON_SPELLCHECKABLE | TextField.NO_LEARNING | RichTextField.USE_TEXT_WIDTH){
            public int getPreferredWidth() {
                return Math.min((Display.getWidth()-20)/2,super.getPreferredWidth());
            }
        };
        key.setPadding(0, 0, 0, 10);
        key.setFont(Fonts.NORMAL);
        add(key);

        value = new LabelField(right,Field.NON_SPELLCHECKABLE | TextField.NO_LEARNING | Field.FOCUSABLE);
        value.setPadding(0, 10, 0, 0);
        value.setFont(Fonts.BOLD);
        add(value);
    }
    public int getPreferredHeight() {
        return Math.max(key.getHeight(), value.getHeight());
    }
    public int getPreferredWidth() {
        return Display.getWidth()-20;
    }
    protected void sublayout(int arg0, int arg1) {
        super.sublayout(arg0, arg1);
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
}

In my application i had to implement custom component that is extended from VerticalFieldManager and this manager holds Rows which are HorizontalFieldManager.
The problem is in OS 4.5 LabelField in the left shows only one line of text. Here is the code and images.BB6.0
enter image description here

class Row extends HorizontalFieldManager{
    private LabelField key;
    private LabelField value;

    public Row(String left,String right){
        key = new LabelField(left + ": ",Field.NON_FOCUSABLE | Field.NON_SPELLCHECKABLE | TextField.NO_LEARNING | RichTextField.USE_TEXT_WIDTH){
            public int getPreferredWidth() {
                return Math.min((Display.getWidth()-20)/2,super.getPreferredWidth());
            }
        };
        key.setPadding(0, 0, 0, 10);
        key.setFont(Fonts.NORMAL);
        add(key);

        value = new LabelField(right,Field.NON_SPELLCHECKABLE | TextField.NO_LEARNING | Field.FOCUSABLE);
        value.setPadding(0, 10, 0, 0);
        value.setFont(Fonts.BOLD);
        add(value);
    }
    public int getPreferredHeight() {
        return Math.max(key.getHeight(), value.getHeight());
    }
    public int getPreferredWidth() {
        return Display.getWidth()-20;
    }
    protected void sublayout(int arg0, int arg1) {
        super.sublayout(arg0, arg1);
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
}

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

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

发布评论

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

评论(1

|煩躁 2025-01-10 13:16:03

我通过将 LabelFields 放置在 VFM 中并覆盖来解决了这个问题
getPreferredHeight()sublayout() 方法如下所示。谢谢史密斯先生

class Row extends HorizontalFieldManager{
    private LabelField key;
    private LabelField value;

    public Row(String left,String right){
        VerticalFieldManager leftVfm = new VerticalFieldManager(){
            public int getPreferredWidth() {
                return Math.min(getField(0).getPreferredWidth(), (Display.getWidth())/2);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(getPreferredWidth(), maxHeight);
                setExtent(getPreferredWidth(), maxHeight);
            }
        };
        VerticalFieldManager rightVfm = new VerticalFieldManager();

        key = new LabelField(label.getLabel() + ": ",Field.FOCUSABLE);
        key.setFont(Fonts.NORMAL);
        leftVfm.add(key);

        value = new LabelField(label.getRight(),Field.FOCUSABLE);
        value.setFont(Fonts.BOLD);
        rightVfm.add(value);

        add(leftVfm);
        add(rightVfm);
    }
    public int getPreferredHeight() {
        if (key != null)
            return Math.max(key.getHeight(), value.getHeight());
        else{
            return value.getHeight();
        }
    }
    public int getPreferredWidth() {
        return Display.getWidth()-20;
    }
    protected void sublayout(int arg0, int arg1) {
        super.sublayout(arg0, arg1);
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
}

I solved the issue by placing LabelFields inside VFM and overrode
getPreferredHeight() and sublayout() methods as shown below. Thanks Mister Smith.

class Row extends HorizontalFieldManager{
    private LabelField key;
    private LabelField value;

    public Row(String left,String right){
        VerticalFieldManager leftVfm = new VerticalFieldManager(){
            public int getPreferredWidth() {
                return Math.min(getField(0).getPreferredWidth(), (Display.getWidth())/2);
            }
            protected void sublayout(int maxWidth, int maxHeight) {
                super.sublayout(getPreferredWidth(), maxHeight);
                setExtent(getPreferredWidth(), maxHeight);
            }
        };
        VerticalFieldManager rightVfm = new VerticalFieldManager();

        key = new LabelField(label.getLabel() + ": ",Field.FOCUSABLE);
        key.setFont(Fonts.NORMAL);
        leftVfm.add(key);

        value = new LabelField(label.getRight(),Field.FOCUSABLE);
        value.setFont(Fonts.BOLD);
        rightVfm.add(value);

        add(leftVfm);
        add(rightVfm);
    }
    public int getPreferredHeight() {
        if (key != null)
            return Math.max(key.getHeight(), value.getHeight());
        else{
            return value.getHeight();
        }
    }
    public int getPreferredWidth() {
        return Display.getWidth()-20;
    }
    protected void sublayout(int arg0, int arg1) {
        super.sublayout(arg0, arg1);
        setExtent(getPreferredWidth(), getPreferredHeight());
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文