0

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.

Terry
  • 989
  • 8
  • 29
Gopinath
  • 23
  • 5
  • you mean by - you have a text box of 100x20. now when you enter text, the text size exceeds the width of text box, so the text box's height will expand to 100x20 . you want like that ?. Specify your need. – Rince Thomas Dec 12 '12 at 07:55
  • Thank you for quick response, yes my texbox dimension is of 150x50 and now the text size exceeds more then one line then height of the textbox need to auto expand of 150x200, in which user can able to see atleast two lines of inputted text. – Gopinath Dec 12 '12 at 08:10

1 Answers1

2

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());
    }
}
Sarah
  • 1,895
  • 2
  • 21
  • 39