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
New Developer
MujibAzizi
Posts: 38
Registered: ‎12-27-2010
My Device: BlackBerry Z10/Q10 - BlackBerry PlayBook
My Carrier: Vodafone NL

label.textHeight returns 0

Hello there!

I am trying to vertically center a Label. So what I did was: 

title.setPosition(185, 150 / 2 - (title.textHeight / 2));

			

 But it didnt work, so I traced out title.textHeight , and strange enough it returns '0'. 

 

This is my entire code:

 

title	=	new Label();
			title.height	=	20;
			title.setPosition(185, 150 / 2 - (title.textHeight / 2));
			title.autoSize	=	TextFieldAutoSize.LEFT;
			title.format	=	textFormat;
			

 

I've also tried it without setting a textformat. 

 

 

Thanks!

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: label.textHeight returns 0

Which Label class? There are many to choose from. What is the line of the import statement?

You are setting the height, why not use that instead?
Please use plain text.
New Developer
MujibAzizi
Posts: 38
Registered: ‎12-27-2010
My Device: BlackBerry Z10/Q10 - BlackBerry PlayBook
My Carrier: Vodafone NL

Re: label.textHeight returns 0

I'm using the following import 

import qnx.fuse.ui.text.Label;

 And I accidently copied the test which I tried, it doenst either work when I set the height. 

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: label.textHeight returns 0

Under the BB10 libraries, I am getting a textHeight for the label. Is this under the PlayBook library or the BB10 library? when are you calling this? During construction or during a refresh (draw/updateDisplayList)? Try delaying the call with either during a frame update/refresh or by using setTimeout.
Please use plain text.
Developer
JohnPinkerton
Posts: 350
Registered: ‎01-21-2011
My Device: Curve 8900 (Personal) / Bold 9650 (Work)
My Carrier: Regional

Re: label.textHeight returns 0

Set the text before you get the textHeight, else if there's no text, the textHeight will return 0.
Please use plain text.