Tushar
Tushar

Reputation: 5955

Set the height and width of EditField on BlackBerry

I want to set the height and width of an EditField in my BlackBerry app.

Upvotes: 1

Views: 3171

Answers (4)

Efe Ariaroo
Efe Ariaroo

Reputation: 1080

Another way to modify the height of an EditField is by fiddling with the padding around the borders like this:

EditField emailField = new EditField("", "optional initial text");

XYEdges xyEdge = new XYEdges(2, 2, 2, 2);
XYEdges xyEdgeColors = new XYEdges(0x00dddddd, 0x00dddddd, 0x00dddddd, 0x00dddddd);
Border aBorder = BorderFactory.createSimpleBorder(xyEdge, xyEdgeColors, Border.STYLE_SOLID);

emailField.setBorder(aBorder);
emailField.setPadding(10, 5, 5, 10);

Upvotes: 0

AmrAngry
AmrAngry

Reputation: 869

  • Note 1 : You can't set the width and height for editField
  • Note 2 : You use just the sublayout method in manager
  • Note 3 : If you add the editField to the screen it will fill all the available width from the beginning to the end of screen

You can use this idea by putting some fields in the left side and putting your editField in the last.

Or, you can use the below code.

You will set the width and height of both the manager and the edit field and try to put them on the screen:

HorizontalFieldManager containerManager = new HorizontalFieldManager() {
    public int getPreferredHeight() {
        return super.getPreferredHeight();
    }

    public int getPreferredWidth() {
        return super.getPreferredWidth();
    } 

    protected void sublayout(int maxWidth, int maxHeight) {
        setExtent(getPreferredWidth(), getPreferredHeight());
        super.sublayout(getPreferredWidth(), getPreferredHeight());
    }
};


EditField editField = new EditField(Field.FIELD_VCENTER) {
    public int getPreferredHeight() {
        // TODO Auto-generated method stub
        return super.getPreferredHeight();
    }

    public int getPreferredWidth() {
        // TODO Auto-generated method stub
        return super.getPreferredWidth();
    } 
};

Upvotes: 1

user1053646
user1053646

Reputation:

You can also pace the edit field inside a horizontalFieldmanager and override the sublayout method to set the height and width of horizontalfieldmanager for setting the height & width of editfield

Upvotes: 3

Richard Le Mesurier
Richard Le Mesurier

Reputation: 29762

You need to override the field's layout method to set the size for you:

protected void layout(int width, int height)
{
    super.layout(customWidth, customHeight);
    setExtent(customWidth, customHeight);
}

where customWidth and customHeight have been set by you elsewhere.

  • super.layout(customWidth, customHeight) lays the field out to use your special width & height.

  • setExtent(customWidth, customHeight) sets the size of the field on the screen.


You can do this when you declare your EditField using code similar to the below code:

final int customWidth = Display.getWidth();
final int customHeight = 30;

Field myEditField = new EditField()
{
    protected void layout(int width, int height)
    {
        super.layout(customWidth, customHeight);
        setExtent(customWidth, customHeight);
    }

};

Upvotes: 8

Related Questions