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
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

QNX Label center justified

[ Edited ]

Has anyone got the label to center justify with wrap around?

 

Sample:

 

var textmsg :Label = new Label();
textmsg.setSize( 300, 200 );
textmsg.textField.wordWrap = true;
textmsg.textField.multiline = true;
			
textmsg.text = 'hello world\nthis is a long text that I want centered and wrap around to look very nice to the user.';
		
textmsg.autoSize = TextFieldAutoSize.CENTER;
addChild( textmsg );

 

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

Re: QNX Label center justified

hey john,

 

im not sure exactly which effect you are going for but by applying a textformat to the label and setting the align to center should center all the text in a label such as follows:

 

 

var textmsg :Label = new Label();
textmsg.setSize( 300, 200 );
textmsg.textField.wordWrap = true;
textmsg.textField.multiline = true;

var myFormat:TextFormat = new TextFormat();
myFormat.align = TextFormatAlign.CENTER;

textmsg.text = 'hello world\nthis is a long text that I want centered and wrap around to look very nice to the user.';

textmsg.format = myFormat;
textmsg.autoSize = TextFieldAutoSize.CENTER;
addChild( textmsg );

 

Hope thats what you are looking for. good luck!

 

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
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: QNX Label center justified

Works great on just text, but if the textField is HTML, it seems to ignore it (using .htmlText).

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

Re: QNX Label center justified

if you are using htmlText chances are you are going to have to use html tags within your string to format it. the only i can think of doing it from the outside like via code is by applying a stylesheet to your label object. do you have a sample of the htmlText you are using?

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
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: QNX Label center justified

Nothing special:

<u>Compass</u>\n<b>Company Name</b>\nCopyright

 

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

Re: QNX Label center justified

hey john,

 

just tried it and it works fine on my end. here is the code im using to test it out. maybe there is something different im doing. also note i applied a red background to show that it is infact centered:

 

 

package
{
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import qnx.ui.text.Label;
	
	[SWF(width="1024", height="600", backgroundColor="#CCCCCC", frameRate="30")]
	public class LabelTest extends Sprite
	{
		public function LabelTest()
		{
			super();
			
			// support autoOrients
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			var textmsg :Label = new Label();
			textmsg.setSize( 300, 200 );
			textmsg.textField.wordWrap = true;
			textmsg.textField.multiline = true;
			
			var myFormat:TextFormat = new TextFormat();
			myFormat.align = TextFormatAlign.CENTER;
			
			textmsg.htmlText = '<u>Compass</u>\n<b>Company Name</b>\nCopyright';
			
			textmsg.format = myFormat;
			textmsg.autoSize = TextFieldAutoSize.CENTER;
			
			textmsg.graphics.beginFill(0xFF0000);
			textmsg.graphics.drawRect(0,0,textmsg.width,textmsg.height);
			textmsg.graphics.endFill();
			
			addChild( textmsg );
		}
	}
}

 

hope that sheds some light. good luck!

 

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
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: QNX Label center justified

Thanks.  It has to do with the order of the calls (not very OO like).  If you try to set the justification after setting the string value with htmlText, the justification is ignored.

 

I am writing my own AlertDialog class system.  I just got tired of not being able to test certain things in AIR.  Same API as the QNX, with some additions.  Hope to have it released in the next week or so.