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

New Developer
Posts: 32
Registered: ‎05-19-2009
My Device: Not Specified
Accepted Solution

How to split the screen vertically?

[ Edited ]

I want to split screen into left and right part. The left part is used to display text with RichTextField and right part is for a button. The code is as following:



final RichTextField text = new RichTextField("Hello World! To create menu items in your own application, extend this abstract class. Your subclasses must implement the Runnable interface, which in turn supports abstract dispatching of menu actions on activation. For example.", Field.NON_FOCUSABLE);

final ButtonField next = new ButtonField("Press me", ButtonField.CONSUME_CLICK);

HorizontalFieldManager hrMgr = new HorizontalFieldManager();

VerticalFieldManager vfMgr1 = new VerticalFieldManager()

public int getPreferredWidth() {
System.out.println("next.getWidth() = " + next.getWidth());
System.out.println("Display.getWidth() = " + Display.getWidth());
return Display.getWidth() - next.getWidth()-20;

protected void sublayout(int maxWidth, int maxHeight) {
System.out.println("getPreferredWidth() = " + getPreferredWidth());

super.sublayout(getPreferredWidth(), text.getPreferredHeight());
setExtent(getPreferredWidth(), text.getPreferredHeight());


VerticalFieldManager vfMgr2 = new VerticalFieldManager();



But there are 2 problems:

1. The button cannot be displayed fully. It become narrow and the text on it disappear.

2. Only first line of text can be displayed and the others disappear.

Is there a way to automatically calculate the width of button and Height of RichTextField.


Thanks a lot!

Message Edited by txj78 on 06-04-2009 03:22 PM
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to split the screen vertically?

Replace your vfMgr1 manager like below:


VerticalFieldManager vfMgr1 = new VerticalFieldManager() { protected void sublayout(int width, int height) { int w = Display.getWidth() - next.getPreferredWidth()-20; Field field; int fieldCount; int x = 0; int y = 0; fieldCount = getFieldCount(); for(int i = 0; i < fieldCount; i++) { field = getField(i); setPositionChild(field, x, y); layoutChild(field, w, height); y += field.getContentHeight(); } setExtent(w, y); } };






New Developer
Posts: 32
Registered: ‎05-19-2009
My Device: Not Specified

Re: How to split the screen vertically?

Thanks bikas. It works. And I found it is better to get w in this way:

int w = Display.getWidth() - vfMgr2.getPreferredWidth();

Otherwise, the text on the button cannot be fully displayed.