Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Developer
dn8
Posts: 46
Registered: ‎06-16-2009
My Device: Not Specified
Accepted Solution

Nested HorizontalFieldManagers

I am not even sure if this is possible, but I am trying to create a dynamic header region by treating H Managers as divs and css, as you would in HTML (sort of)

 

Is this even possible? With the code below I only end up with the 46px blue box (container) .

The logo is not being drawn, nor are the 1 pixel and 2 pixel lines that are supposed to appear under the blue box.

 

jde 4.2.1

 

    public static HorizontalFieldManager header()
    {
        BitmapField logo = new BitmapField(Bitmap.getBitmapResource("images/logo.png"));
        HorizontalFieldManager container = new HorizontalFieldManager()
        {
            protected void paint(Graphics g)
            {
                g.setBackgroundColor(0x024c87);
                g.clear();
                super.paint(g);
            }

            protected void sublayout(int width, int height)
            {
                height = 46;
                width = Display.getWidth();
                super.sublayout(width, height);
                setExtent(width, height);
            }
        };

        HorizontalFieldManager head = new HorizontalFieldManager()
        {
            protected void sublayout(int width, int height)
            {
                height = 43;
                width = Display.getWidth();
                super.sublayout(width, height);
                setExtent(width, height);
            }
        };

        HorizontalFieldManager OnePixel = new HorizontalFieldManager()
        {
            protected void sublayout(int width, int height)
            {
                height = 1;
                width = Display.getWidth();
                super.sublayout(width, height);
                setExtent(width, height);
            }

            protected void paint(Graphics g)
            {
                g.setBackgroundColor(0x195f96);
                g.clear();
                super.paint(g);
            }
        };

        HorizontalFieldManager TwoPixel = new HorizontalFieldManager()
        {
            protected void sublayout(int width, int height)
            {
                height = 2;
                width = Display.getWidth();
                super.sublayout(width, height);
                setExtent(width, height);
            }

            protected void paint(Graphics g)
            {
                g.setBackgroundColor(0xa5b6c2);
                g.clear();
                super.paint(g);
            }
        };

        head.add(logo);
        container.add(head);
        container.add(OnePixel);
        container.add(TwoPixel);

        return container;
    }

 

 

 

Please use plain text.
Developer
Developer
dn8
Posts: 46
Registered: ‎06-16-2009
My Device: Not Specified

Re: Nested HorizontalFieldManagers

No one??

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Nested HorizontalFieldManagers

[ Edited ]
public class SpacerField extends Field {

    private int _height;

    /**
     * Constructors
     */
    public SpacerField() {
        this(2);
    }

    public SpacerField(int height) {
        super(Field.READONLY);
        _height = height;
    }

    public void layout(int widht, int hieght) {
        setExtent(Display.getWidth(), _height);
    }

    public void paint(Graphics g) {
// Add code to colur in SpacerField here.....
    }

}

 

HorizontalFieldManagers lay things out horizontally.  You want the the Fields laid out vertically don't you, so your container should be a VerticalFieldManager.

 

Also I would not use a HorizontalFieldManager to provide a colored 'spacer' region, that seems like overkill.  You can do exactly the same with a Fields.  See above (and I've just created this, so it might not compile).

 

Sorry for some reason it decided I wanted to add the code before the text.  ah well.

 

 

 

 

Please use plain text.
Developer
Developer
dn8
Posts: 46
Registered: ‎06-16-2009
My Device: Not Specified

Re: Nested HorizontalFieldManagers

Doh! Stupid mistake... For some reason I was thinking they would blow each other out to the next line...

 

Thanks Peter!

Please use plain text.