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

Adobe AIR Development

Reply
Developer
Posts: 83
Registered: ‎10-26-2008
My Device: Z10
My Carrier: MTS UKR
Accepted Solution

Width of TextField

Hello,

 

Is it possible to create single-line TextField with predefined width to keep X characters? I mean displayable width (not maxChars) when border is visible.

 

 

Thanks

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Width of TextField

Not exactly.  Each character has a different pixel width ('W' vs 'i').  I would determine the pixel width to hold x number of 'W' to determine the size on the screen ( and set maxChars ).

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Width of TextField

Depending on what you're trying to do specifically, one option that may work is to change your font to a fixed-pitch font.  Courier is a common one though there's also a BBAlpha Mono and others.  In a fixed-pitch (also known as "monospace") font, all characters are the same width.

 

There are also flash APIs for font metrics and such that will let you discover the exact pixel size of various characters or pieces of text at various font sizes.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Width of TextField

Hey,

Are you using a TextField object specifically or the qnx label / textinput object? Wat exactly are u trying to end up with? We can probably figure out a way programatically to handle the visibility of the characters.
J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Developer
Posts: 83
Registered: ‎10-26-2008
My Device: Z10
My Carrier: MTS UKR

Re: Width of TextField

Thanks.

 

It will contain only numbers.

How I can calculate width of string such "99.99" using specific font settings?

How I can set width of TextField?

Is it possible to draw TextField's background as rounded rect?

Developer
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Width of TextField

Hey,

You can most likely accomplish this by using the .graphics package and its functions (drawRoundedRect). I'm not near a computer but once I get on to it ill post up a sample code once I figure it out (unless someone beats me to it hah). Also have u tried the .textWidth property to retrieve the width of ur text? Is it accurate?
J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Highlighted
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Width of TextField

Are you entering the number and you want the size of the entry to change with the numbers entered?

Or, is the values just a read-only label that you want to just have a bounding box (rounded) around it?

Developer
Posts: 83
Registered: ‎10-26-2008
My Device: Z10
My Carrier: MTS UKR

Re: Width of TextField


jtegen wrote:

Are you entering the number and you want the size of the entry to change with the numbers entered?

Or, is the values just a read-only label that you want to just have a bounding box (rounded) around it?


I'm entering numbers but I wish that TextField has static width which can keep maxChars. So there are 2 questions:

1. How to me measure text;

2. How to setup width of TextField

 

Thanks

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Width of TextField

You can measure text using flash.text.TextField.getLineMetrics().  You should be able to find numerous examples on the web.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 83
Registered: ‎10-26-2008
My Device: Z10
My Carrier: MTS UKR

Re: Width of TextField

 


peter9477 wrote:

You can measure text using flash.text.TextField.getLineMetrics().  You should be able to find numerous examples on the web.


 

Cool. Thanks.

How to set TextField's width? It doesn't has setSize() method.