Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

how to center Basic edit field

i have basic edit filed and cau u tell me how to display it in center


public final class MyScreen extends MainScreen
BasicEditField bf;
LabelField lbl;

public MyScreen()

bf = new BasicEditField("week ",null, 10, Field.FIELD_HCENTER)

protected boolean navigationClick(int arg0, int arg1) {
// TODO Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable()
public void run()
DateTimePicker datePicker = DateTimePicker.createInstance(null, DateFormat.DATE_MEDIUM, 0);

return true;


Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to center Basic edit field

The problem with BasicEditField is that is always thinks if should take up the full width of the screen to give the user as much space as possible to type into.  So Field.FIELD_HCENTER does nothing since it is the full width.  So you need to restrict the width it uses, which is of course problematic because it depends on the Font and the number of characters the user has typed in.  The easiest approach is to restrict the number of characters the user can type in (See the constructor arguments for that), then override the layout() method and restrict the width based on the number of characters in the Label, plus the number of characters you allow, using using the Font that you have specified for the Field.  Then it will be centered based on this width. 


See here for more on creating your own Fields: