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
thebbk
Posts: 26
Registered: ‎11-27-2008
My Device: Not Specified

UI - Can you place VerticalFieldManagers on Managers?

[ Edited ]

I am really struggling with the arrangement of UI pieces. If anyone knows where I can find the updated PDF for the applications developer guide, Id really appreciate it!The version I have is from 4.1 and I am using 4.7

 

Anyway, I have a very simple app which I am using to learn how to size and position fields and managers. 

 

In this example, I have a class that extends Manager - which fills the top half of the screen red. I then try to place a class on the Manager - that extends VerticalFieldManager (GreenBox) which should fill the top 1/4 of the screen green. 

 

When I run this, I only see the red on the top half of the screen. There is no green. 

 

Is it possible to place VerticalFieldManagers on Managers?

 

Code: Main App Class:

 

public class Layouts extends UiApplication
{

    public static void main(String[] args)
    {
        Layouts theApp = new Layouts();
        theApp.enterEventDispatcher();
    }
   
    public Layouts()
    {
        super();
        MainScreen screen = new MainScreen();
        screen.setTitle("Using Different Managers");
        ComponentManager componentManager = new ComponentManager( 0 );
        //add the green field to the component manager
        GreenBox greenBox = new GreenBox();
        componentManager.add( greenBox );
        screen.add(componentManager);
        pushScreen( screen );
    }
}

 

Code: - The Manager which paints the top half screen red:

 

public class ComponentManager extends Manager
{

    ComponentManager( long style )
    {
        super( style );
    }
   
    public void paintBackground( Graphics g )
    {
        g.setBackgroundColor( Color.RED );
        g.clear();
    }
   
    protected void sublayout(int width, int height)
    {
        XYRect extent = getExtent();
        XYRect rect = this.getManager().getContentRect();
        int awidth = Math.max( extent.width, rect.width );
        int aheight = ( Math.max( extent.width, rect.height ) ) / 2;
        setExtent( awidth, aheight );
    }
   
    public int getPreferredWidth()
    {
        return Display.getWidth();
    }
   
    public int getPreferredHeight()
    {
        int aheight = 0;
        XYRect extent = getExtent();
        aheight = Math.max( extent.height, Display.getHeight() ) / 2;
        return aheight;
    }
}

 

Code: VerticalFieldManager which paints the top 1/4 of the screen green (top half of the Manager below)

 

public class GreenBox extends VerticalFieldManager
{
    public GreenBox()
    {
        super( Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR );
    }
   
    public void paintBackground( Graphics g )
    {
        g.setBackgroundColor( Color.GREEN );
        g.clear();
    }
   
    protected void sublayout(int width, int height)
    {
        int awidth = 0;
        int aheight = 0;
   
            XYRect extent = getExtent();
            XYRect rect = this.getManager().getContentRect();
            awidth = Math.max( extent.width, rect.width );
            aheight = ( Math.max( extent.width, rect.height ) ) / 2;
       
        setExtent( awidth, aheight );
    }
   
    //this can be full screen width
    public int getPreferredWidth()
    {
        return Display.getWidth();
    }
   
    //Make this 1/2 the height of the manager it rests on.
    public int getPreferredHeight()
    {
        XYRect rect = this.getManager().getContentRect();
        return rect.height / 2;
    }
}

 

Any Ideas?

 

 

 

 

Message Edited by thebbk on 01-17-2009 05:23 PM
Message Edited by thebbk on 01-17-2009 05:24 PM
Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: UI - Can you place VerticalFieldManagers on Managers?

You can find most things you want from here:

http://na.blackberry.com/eng/developers/

 

There clicks from there and I'm here:

http://na.blackberry.com/eng/support/docs/subcategories/?userType=21&category=BlackBerry+Java+Applic...

This is the 4.7 doc for you.

 

The rest is a little more difficult.  I will look later, if someone else doesn't beat me to it

 

Developer
webmasterpdx
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: UI - Can you place VerticalFieldManagers on Managers?

I don't have time to go through your code in detail, but I found everything I needed here:

 

http://na.blackberry.com/eng/support/docs/subcategories/?userType=21&category=BlackBerry+Java+Applic...

 

You can search all the docs from there too.

Remember that you really can't doi too many columns on the blackberry so it shouldn't be as complex as say a PC app. Having 2 vertical managers inside a horizontal manager. This will place the 2 vertical managers as columns and you can place the controls in 2 vertical columns then.

Good luck.

-Donald

 

 

Developer
peter_strange
Posts: 19,612
Registered: ‎07-14-2008
My Device: Not Specified

Re: UI - Can you place VerticalFieldManagers on Managers?

[ Edited ]

There does appear to be a typo:

aheight = ( Math.max( extent.width, rect.height ) ) / 2;

Should this be?

aheight = ( Math.max( extent.height, rect.height ) ) / 2;

 

I think you will find the following useful:

 

How to - Create a custom layout manager for a screen
Article Number: DB-00117 
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

How to - Use the User Interface API to create an editable table
Article Number: DB-00130
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

Message Edited by peter_strange on 01-18-2009 02:00 AM