Welcome!

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

Reply
New Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Storm 9550
My Carrier: Verizon

How to change the size of a TextField

Simple question really. How do I change the size of a TextField?

 

The samples and docs i've read state to use the Manager to resize it. It just seems so complicated to do something that I believe should be so simple.

 

Basically I need to position a text field to accept a number somewhere on the right side of the screen that fits about 3 chars wide.

 

I also need to position some labels

 

Thanks for the help. F1 should have some samples, RIM!

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: How to change the size of a TextField

[ Edited ]

Have you tried TextField.setMaxSize?  Or using constructors which specify maximum number of characters (instead of relying on DEFAULT_MAXCHARS, which is a million)?

 

In addition, if you want to limit the visible size of the field so that something can fit to the right of it, you should override layout() like this:

protected void layout(int w, int h) {
  Font myFont = getFont();
  int myWidth = myFont.getAdvance(getLabel()) + myFont.getAdvance("W") * getMaxChars();
  myWidth = Math.min(myWidth, w);
  layout(myWidth, h);
}

 

 

 

 I'm using 'W' as the widest character.  You can go with something like "0" or "8" for numeric-only fields.

 

Edit: for some reason, forums bolded most of my message.  Removing that bold attribute.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Contributor
Posts: 6
Registered: ‎08-04-2010
My Device: Storm 9550
My Carrier: Verizon

Re: How to change the size of a TextField

'll try that, see I'm just accostumed to visual programming and so much code to set a size seems like too much of a hassle where as I should be focusing on logic. But I guess this isin't Windows :smileytongue: