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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
Paratheo
Posts: 97
Registered: ‎04-25-2009
My Carrier: AT&T
Accepted Solution

How to align RichTextField to center?

Hey all,

 

Been picking at this for quite some time, using solutions found on many forums. Still unable to get it right. I have this simple about screen in my application, and i simply want all the lines of text to be centered on screen Horizontally, and Vertically too if that works. What am I doing wrong here?

 

 

package com.rim.samples.device.helloworlddemo;


import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;


public class AboutScreen extends MainScreen {

	/**
	 * 
	 */
	public AboutScreen() {
		super(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
		
		VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_HCENTER){
			protected void sublayout(int maxWidth, int maxHeight) { 
				 
                super.sublayout(Display.getWidth(),Display.getHeight()); 
                setExtent(Display.getWidth(),Display.getHeight());

            } 

	    };
		vfm.add(new RichTextField("Lead Developer - Xxxx Xxxxxxx", Field.NON_FOCUSABLE | 			Field.FIELD_HCENTER));
		vfm.add(new RichTextField("For Support - xxxxxxxx@gmail.com", Field.NON_FOCUSABLE | 	Field.FIELD_HCENTER));
		vfm.add(new RichTextField("Follow us on Twitter - @xxxxxxxxxx", Field.NON_FOCUSABLE | 	Field.FIELD_HCENTER));
		vfm.add(new RichTextField("Version - 1.0.0", Field.NON_FOCUSABLE | Field.FIELD_HCENTER));
		add(vfm);
		
	}
	
	
}

 

 

Thanks,

 

Theodore M.

Please use plain text.
Contributor
EricTheRed03
Posts: 32
Registered: ‎08-13-2012
My Carrier: Rogers

Re: How to align RichTextField to center?

Could you try putting the RichTextField in a GridFieldManager?

 

so it would look something like

 

o=empty field

x=richtextfield

 

----- Grid Field Manager  ----

|o|o|o|

|o|x|o|

|o|o|o|

Please use plain text.
Regular Contributor
Paratheo
Posts: 97
Registered: ‎04-25-2009
My Carrier: AT&T

Re: How to align RichTextField to center?

I appreciate the response, but I dont feel that would solve my problem. All i need to to is align the text in the horizontal center of the screen. There must be some error in the properties i set in my code above or something.

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Carrier: various

Re: How to align RichTextField to center?

Try creating your RichTextField with TEXT_JUSTIFY_HCENTER (TEXT_ALIGN_HCENTER before OS 7.0) flag. FIELD_HCENTER tells the Manager where to put the field during layout. Those TEXT_ALIGN/TEXT_JUSTIFY flags tell the field how to display the text.

You might want to drop FIELD_HCENTER and use USE_ALL_WIDTH combined with that TEXT_JUSTIFY/TEXT_ALIGN flag - see what looks better.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Regular Contributor
Paratheo
Posts: 97
Registered: ‎04-25-2009
My Carrier: AT&T

Re: How to align RichTextField to center?

K so i ended up solving it easily using the following property in each RichTextField object-

 

RichTextField.TEXT_ALIGN_HCENTER

 

 

And that solved it all.

Please use plain text.
Super Contributor
lyon819
Posts: 253
Registered: ‎08-19-2010
My Carrier: TT

Re: How to align RichTextField to center?

_rtf = new RichTextField("BlueTooth connection stop...", RichTextField.NON_FOCUSABLE | RichTextField.TEXT_JUSTIFY_HCENTER);

 

RichTextField.TEXT_ALIGN_HCENTER is Deprecated.

 

 

Cheers.

 

-Fight with BB10
Please use plain text.