0

我已经在我的应用程序中实现了自定义文本框,它运行良好,但现在客户需要在键入(BBM 聊天文本框)时自动扩展文本框。有什么方法可以覆盖默认的 Editfield 以自动扩展。请给我建议。

4

1 回答 1

2

这可能会做你想做的事;自动增加 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());
    }
}
于 2012-12-12T08:19:53.397 回答