0

I am writing an application in BlackBerry, where I want to do some custom painting at the top portion of the screen in the paint method of FullScreen and at the same time, I want a RichtextField positioned at the lower portion of the screen. I tried using setPosition methods in the Field class, but to no avail. So how do I set the position of the RichtextField that is added to the FullScreen class?

Prabhu R
  • 13,836
  • 21
  • 78
  • 112

2 Answers2

1

The best way to position objects is to extend a Manager and use it to position and size the objects the way you want. Check the documentation for net.rim.device.api.ui.Manager and net.rim.device.api.ui.Field for information on how manager control their children.

Richard
  • 8,920
  • 2
  • 18
  • 24
  • FullScreen extends Manager, however when I tried to use setPositionChild() method, it threw an IllegalArgumentException saying that the Field is not a child. I have added the field to the FullScreen. Also I searched if I need to set it as a child, but there were no methods to do that. – Prabhu R Aug 20 '09 at 12:47
1

You can use a SpacerField for that purpose:

class SpacerField extends Field {

  int localWidth, localHeight;

  SpacerField(int width, int height) {
    super(Field.NON_FOCUSABLE);
    localWidth = width;
    localHeight = height;
  }

  protected void layout(int width, int height) {
    // TODO Auto-generated method stub
    setExtent(localWidth, localHeight);
  }


  protected void paint(Graphics graphics) {

  }


  public int getPreferredWidth() {
    return localWidth;
  }

  public int getPreferredHeight() {
    return localHeight;
  }
}

and add it to your Screen before your RichTextField. Be sure to give a suitable width (Display.getWidth() ?) and height when constructing the SpacerField.

Note: I had found the code at this forum discussion a few months ago when I needed to do something similar.

paracycle
  • 7,665
  • 1
  • 30
  • 34