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
New Developer
Posts: 15
Registered: ‎08-31-2010
My Device: Not Specified
Accepted Solution

Labels are centered but Text Fields are not

I can't seem to persuade a RichTextField to be centered on the screen.  Is this a limitation of this particular field, or am I doing something stupid?  This code illustrates the problem:

 

 

package com.rim.samples.hello;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

final class HelloScreen extends MainScreen {
    public HelloScreen () {
        super();
        
        // The title is centered
        LabelField title = new LabelField("Test Field Attributes",
                LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.HCENTER
                | LabelField.VCENTER);
        setTitle (title);

        // A simple label added to the main screen is centered
        add (new LabelField("Yay! I'm centered!", LabelField.FIELD_HCENTER));
        
        // But a rich text field refuses to center
        add (new RichTextField("Boohoo, I'm not!", RichTextField.FIELD_HCENTER));

        add (new LabelField("Labels rock!", LabelField.FIELD_HCENTER));

        // The vertical field manager makes no difference
        VerticalFieldManager v = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
        v.add (new RichTextField("field managers don't help :(", RichTextField.FIELD_HCENTER));
        v.add (new LabelField("VFM Labels work!", LabelField.FIELD_HCENTER));
        add(v);
        
    }
}


I've tried FIELD_RIGHT but when HCENTER doesn't work, neither does RIGHT.  I guess I can use a label instead but I was really hoping to use a centered text edit field.  Any ideas?  Thanks,

 

Blister

Highlighted
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Labels are centered but Text Fields are not

The default behavior of RichTextField is to use all width. Try adding the style RichTextField.USE_TEXT_WIDTH




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Developer
Posts: 15
Registered: ‎08-31-2010
My Device: Not Specified

Re: Labels are centered but Text Fields are not

Thanks, that works.