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
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified
Accepted Solution

How to anchor a field to the bottom of the screen

I need to anchor something to the bottom of the screen,

so that it cannot be pushed down any furhter.

 

For example three "regions" of the visiable screen should be split as follows:

 

-----------

|   r1   |

-----------

-----------

|   r2   |

-----------

-----------

|   r3   |

-----------

 

The size of r1 and r3 would be completely static,

and they should never scroll.   r1 is anchored to the

top, r3 anchored to the bottom.  r2 should scroll if

its content is bigger than the available space but never

push the regions above or below it.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen

[ Edited ]
You need to write a custom layout Manager class. This is well covered in the samples and the JDE developer guide.
Message Edited by RexDoug on 10-17-2008 06:25 PM
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen

Alternatively, use MainScreen.  MainScreen has a title and status area, that are respectively the top and bottom of the screen.  So you can do stuff like:

  

VerticalFieldManager vfmTop - new VerticalFieldManager()

vfmTop.add(new CheckboxField("in title", false));

vfmTop.add(new RichTextField("Also in title Area"));

myMainScreen.setTitle(vfmTop);

 

Now the CheckboxField and the text will stay at the top of the screen.

 

You can do exactly the same with another VerticalFieldManager, then use setStatus.

 

Only one 'issue'.  There is a margin inserted automatically between the 'setTitle' area and the rest of the Screen.  This varies by device and/or OS Level. This may be annoying enough for you to want to do your own thing using a Custom Manager.

Developer
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen

[ Edited ]

Thanks for the tips.  I've made some progress .. in case it helps anyone else.  Also maybe this

will help you guys understand what I'm trying to achieve, so you can tell me a cleaner way if

there is one.

 

What I did was to use a MainScreen,and added r1 as the title:

 

 

setTitle(r1);

 

 

 

 

Then for r2 (the one I want to make sure it is a specific size so it doesn't push r3 off the bottom of the screen), I overrode a VerticalFieldManager like this:

 

 

final int maxheight = 125; // <--- hardcoded value for r2 height

VerticalFieldManager r2 = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) {

final static int PADDING_VERTICAL = 3;
final static int PADDING_HORIZONTAL = 6;

protected void sublayout(int width, int height) {
int iYPos = PADDING_VERTICAL;

int fieldCount = getFieldCount();

for (int i = 0; i < fieldCount; i++)
{
Field field = getField(i);
setPositionChild(field, PADDING_HORIZONTAL, iYPos);
layoutChild(field, width, height);
iYPos = iYPos + field.getHeight() + PADDING_VERTICAL;

}
setExtent(width, maxheight); // <-- forces height

}
};

 

 And then I added a few things to r2:

 

 

r2.add(new LabelField("Hello"));
r2.add(new LabelField("Hello2"));

 

 Added r2 to the MainScreen (not shown), and then added r3 to the MainScreen (not shown)

The end result is that r1 sits at the top, r2 has a few fields and then a whitespace area below it (its forced to a specific height and the fields only take up part of that), and r3 is "anchored" to the bottom ( actually more like "pushed" ).  This is a big improvement over what I had before -- r3 started right where r2 finished, and there was a big white space between r3 and the bottom of the screen.

 

I still need to test what hapens if I add more LabelFields to r2 that will exceed the hardcoded height of 125 for that region.  Hopefully it will add a scrollbar. 

 

 

 

 

Message Edited by branchcut on 10-17-2008 08:51 PM
Message Edited by branchcut on 10-17-2008 08:53 PM
Developer
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen


branchcut wrote:

I still need to test what hapens if I add more LabelFields to r2 that will exceed the hardcoded height of 125 for that region.  Hopefully it will add a scrollbar. 

 

 


 

I tried adding about 10 label fields to r2, which made the region much larger than the vertical extent I set for it, and it did not push r3 down.  (yay)  OTOH I did not get a scrollbar, but that was not all that important in my case.  But if anyone knows how to get a scrollbar I'd be grateful.

 

Developer
Posts: 46
Registered: ‎07-12-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen

I've found that if I use the setBanner method there is no margin between the top fields and the rest of the screen...
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen

If you look at the following thread, it would seem the lack of scrollbars is a known problem:

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=6179&query.id=213...

 

I see you are now using the Title area for R1,  Is there any reason why you don't use the Status area for r3 in the same way (i.e. MainScreen.setStatus(r3)Smiley Wink.  This will mean you can use the 'native' MainScreen processing which does display the Scroll bars.

Developer
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified

Re: How to anchor a field to the bottom of the screen

 


peter_strange wrote:

I see you are now using the Title area for R1, Is there any reason why you don't use the Status area for r3 in the same way (i.e. MainScreen.setStatus(r3)Smiley Wink. This will mean you can use the 'native' MainScreen processing which does display the Scroll bars.


 

Works perfectly. That is exactly what I wanted to achieve, and now I can throw away that sublayout stuff. (Oh well, it was an interesting learning exercise.)

 

/me bows humbly