Blackberry RichTextField preferred height during layout

Posted by James Veenstra on Stack Overflow See other posts from Stack Overflow or by James Veenstra
Published on 2010-03-28T20:31:48Z Indexed on 2010/03/28 20:33 UTC
Read the original article Hit count: 215

Filed under:

This is using the Backberry JDK (5.0 if needed).

I have a custom Manager that contains a RichTextField. I want the height of the field to vary by the amount of text in the RichTextField.

The sublayout code looks like this (rtf is a RichTextField object):

    protected void sublayout(int width, int height) {
    int h = rtf.getPreferredHeight();
    setExtent(Display.getWidth(), h);
    layoutChild(rtf, Display.getWidth(), h);
    setPositionChild(rtf, 0, 0);

    setExtent(Display.getWidth(), h);
}

The call to rtf.getPreferredHeight always returns the same value, no matter how much text (and therefore how many lines on the screen).

Any clues on how to get the height of a RichTextField when the content and width are known?

© Stack Overflow or respective owner

Related posts about blackberry