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

Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Label width

Hi, I have the simplest question to which I cannot find the answer to Smiley Sad


When adding label


import qnx.fuse.ui.text.Label;

var label:Label = new Label(); label.text = "Hello World"; label.width = label.textWidth; addChild(label);

I know that the width = 0 since textWidth doesn't return the actual width of the text right after it have been set. However, if I simply addChild(label), the text is cut off since the label doesn't automatically resize itself... How would I go about auto sizing the label?


Merry Christmas Eve everyone!

Twitter: @gyubok
Posts: 194
Registered: ‎11-12-2010
My Device: Not Specified

Re: Label width

[ Edited ]

yes, it seems a slightly bizarr implementation - by default a label seems to have a width of somthing like 90 and since it will truncate your text, the textWidth it returns will never be more than this default width ...


Here is a way around that:

var label:Label = new Label();

// give it all the space you can, to let it do the initial layout without trunkation
label.width = stage.stageWidth;

label.text = "Hello World";

// force rendering 

// now shorten the label to what is really needed
label.width = label.textWidth;

There might be a more elegant solution, but this seems to work.



The last line assumes that you can reasonably expect the label to be shorter than the availalble width.

I guess, something like this would be better - just to be safe ...

// now shorten the label to what is really needed or truncate to available width
label.width = Math.min(myLabel.textWidth, stage.stageWidth);



My app : Get set - Get up!   Get ready for the snooze revolution.