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
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer
Accepted Solution

How to make a labelfield text right aligned

I want to make my label field text right aligned in then screen

 

LabelField content = new LabelField(description,LabelField.FOCUSABLE|USE_ALL_WIDTH|FIELD_RIGHT)

 This labelfield i am adding to a inner VFM

 

VerticalFieldManager vfm = new VerticalFieldManager (
				VerticalFieldManager .VERTICAL_SCROLL
						| VerticalFieldManager .FOCUSABLE) {
			protected void sublayout(int width, int height) {

				super.sublayout(Display.getWidth() - 20, height);
				setExtent(Display.getWidth() - 20, 33);
			}
		};

 Than this inner vfm i am adding to a outer vfm called main vfm and setting its position

 

layoutChild(vfm, maxWidth, maxHeight);
					setPositionChild(vfm,290, 123);

 

My screen is 320x240

 But the text is going out of the screen.Plz help

 

 

 


 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to make a labelfield text right aligned

[ Edited ]

Forget all the positioning in the Manager and just try this:

 

LabelField content = new LabelField(description,LabelField.FOCUSABLE|DRAWSTYLE.RIGHT);

 

Ad this to a VerticalFieldManager or directly to your MainScreen and I think it should work for you.

 

If not, let us know and we can look at the positioning of the Field.

 

As a side note, this looks dubious:

protected void sublayout(int width, int height) {
super.sublayout(Display.getWidth() - 20, height);
setExtent(Display.getWidth() - 20, 33);
}

What are you trying to do?  Why is 33 important?

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

Re: How to make a labelfield text right aligned


peter_strange wrote:

 

As a side note, this looks dubious:

protected void sublayout(int width, int height) {
super.sublayout(Display.getWidth() - 20, height);
setExtent(Display.getWidth() - 20, 33);
}

What are you trying to do?  Why is 33 important?



Worse yet - the manager will think it's got one height while in fact it has another. This is a great way to confuse it completely and get all kinds of visual artifacts. If (display width - 20) and 33 are so crucial, the manager should be created with USE_ALL_WIDTH | USE_ALL_HEIGHT and only super.sublayout(Math.min(Display.getWidth()-20, width), Math.min(33, height)) should be called from its sublayout. The extent will be properly set by super.sublayout then.

 

And, just like Peter said, DrawStyle.RIGHT is the proper way to align text within the label field. FIELD_RIGHT is a signal to the parent manager to position the field itself accordingly.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: How to make a labelfield text right aligned

Thnx it worked for me