0

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());
    }
}
Ahmet Gulden
  • 2,063
  • 2
  • 15
  • 23
  • Put your `LabelFields` inside `VerticalFieldManagers`, then add these to the `HorizontalFieldManager` of each row. BTW, why are you using `RichTextField.USE_TEXT_WIDTH` in the key's label? LabelField doesn't extend from rtf, so it may give you unexpected results. The same with `TextField.NO_LEARNING`. – Mister Smith Feb 08 '12 at 13:59
  • With using only `Field.NON_FOCUSABLE` and `Field.FOCUSABLE` styles and putting LabelFields inside VFMs, i tried and got same result. – Ahmet Gulden Feb 08 '12 at 14:14
  • Of course, it has nothing to do with those flags. The problem is that the guys at RIM change behavior with each release. – Mister Smith Feb 08 '12 at 14:25
  • So to get the requested result, what should i do? – Ahmet Gulden Feb 08 '12 at 14:26
  • The interesting part is why do second LabelField behave normal while the first one does not. – Ahmet Gulden Feb 08 '12 at 14:28
  • The easiest fix is probably to place the labels inside VerticalFieldManagers to try to enforce that they are displayed. Not sure it will work but have a try. – Mister Smith Feb 08 '12 at 14:30
  • I tried already when you said first time, but i got the same output again. – Ahmet Gulden Feb 08 '12 at 14:40

1 Answers1

1

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());
    }
}
Community
  • 1
  • 1
Ahmet Gulden
  • 2,063
  • 2
  • 15
  • 23