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: 490
Registered: ‎07-16-2008
My Device: Not Specified
Accepted Solution

How to set center alignment on TextField ?

Hi guys.

 

I've not found the way to set center alignment on TextField?

 

Do you know how to set center alignment on TextField ?

 

Please share your knowledge.

 

Thanks.

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to set center alignment on TextField ?

Hi,

 

Hope this will help you

 

import net.rim.device.api.ui.component.BasicEditField;

 

class CustomTextField extends BasicEditField{
    CustomTextField() {
       super(BasicEditField.FIELD_HCENTER | BasicEditField.FIELD_VCENTER);  
    }
   
     public void layout(int width, int height){
         super.layout(getPreferredWidth(),getPreferredHeight());
         setExtent(getPreferredWidth(),getPreferredHeight());
    }
   
   
   
    public int getPreferredHeight(){
        System.out.println("---------------------------------------");
         return 50;
    }
   
    public int getPreferredWidth(){
        System.out.println("#######################################");
         return 120;
    } 
   
}

 

Now in your class which extends MainScreen or FullScreen add object of this class.

 

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: How to set center alignment on TextField ?

Thanks for your response.

So, I need only center alignment of TextField.

 

Do you have an experience related it ?

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: How to set center alignment on TextField ?

Hi,

 

As i know all textField by default take full width of the screen as there width so without overridding there getPrefferedWidth() we cannot make them center align.

 

May be there is some other way to do it.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Highlighted
Developer
Posts: 490
Registered: ‎07-16-2008
My Device: Not Specified

Re: How to set center alignment on TextField ?

Ok. Thanks.

I got it.