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
Contributor
sanghamitra_83
Posts: 17
Registered: ‎08-06-2012
My Carrier: Vodaphone
Accepted Solution

BasicEditField : set Focus

Hi,

If  I don't override the layout() method of the basicEdit field, it takes entire screen width.

The following code creates a EditField, But I can't set the focus on it, whatever I type I can't see either.

 

I tried overridding the paint() method. still not working.

 

Please Guide me.

 

 

background = BackgroundFactory.createSolidBackground(Color.WHITE);
        
        statusMsgFieldEdit = new BasicEditField("", statusMsg, 140, FOCUSABLE){
              protected void layout(int width, int height){       
                    width = 200;
                    height = 40;
                    setExtent(width, height);
                }

                public int getPreferredHeight(){
                    return 40;        
                }

                public int getPreferredWidth(){
                    return Display.getWidth();
                }
        };
        statusMsgFieldEdit.setBackground(background);

Please use plain text.
Developer
simon_hain
Posts: 15,558
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: BasicEditField : set Focus

it is normal that editfields take the full width of the screen.
i would suggest to override the layout in the manager, not in the field.
see
http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
peter_strange
Posts: 19,526
Registered: ‎07-14-2008

Re: BasicEditField : set Focus

The other thing is that you need to tell the EditField what its bounds are so that it can sort out its won alignment.  So instead of:

 

             protected void layout(int width, int height){       
                    width = 200;
                    height = 40;
                    setExtent(width, height);
                }

You should really do

 

             protected void layout(int width, int height){       
                    width = 200;
                    height = 40;
                    super.layout(width, height);
                }


Please use plain text.
Contributor
sanghamitra_83
Posts: 17
Registered: ‎08-06-2012
My Carrier: Vodaphone

Re: BasicEditField : set Focus

Hi,

 

Thanks.

 

super.layout() fixed the issue.

 

Please use plain text.