Q:

Auto Expand Textbox in Blackberry

I have implemented the Custom Textbox in my app and it works well but now client need is to auto expand the texbox while typing like (BBM chat textbox ). Is there any way to override defualt Editfield to auto expand. Please suggest me.

A:

This might do what you want; auto increase the height of the EditField:
class MyEditField extends EditField
{
    public MyEditField (long style)
    {
        super (style);
        setBorder (BorderFactory.createSimpleBorder(new XYEdges (1, 1, 1, 1)));
    }

    public int getPreferredHeight()
    {
        return Font.getDefault.getHeight() * 3; //setting the height of edit field as 3 rows
    }

    public void layout (int width, int height)
    {
        super.layout (width, height);
        if (getExtent().height < getPreferredHeight())
            setExtent (width, getPreferredHeight());
    }
}

