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
Developer
pankajace12
Posts: 188
Registered: ‎04-30-2011
My Carrier: Airtel

Re: Draw rectangle on the background of label

Hello,

override the layout method.

Thanks
pawan
Please use plain text.
Regular Contributor
techie
Posts: 77
Registered: ‎05-21-2012

Re: Draw rectangle on the background of label

Ok i guess theres no other way than using layout in this case.Thanks for the help.
Please use plain text.
Developer
pankajace12
Posts: 188
Registered: ‎04-30-2011
My Carrier: Airtel

Re: Draw rectangle on the background of label

Hi Techie

 

Try this, if you want to customize the height and widht of EditField.

 

EditField e = new EditField(){
                	protected void layout(int w, int h)
                	{
                		super.setExtent(w, h);
                		super.layout(w, h);
                	}
                };

 Thanks

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

Re: Draw rectangle on the background of label


pankajace12 wrote:

Hi Techie

 

Try this, if you want to customize the height and widht of EditField.

 

EditField e = new EditField(){
                	protected void layout(int w, int h)
                	{
                		super.setExtent(w, h);
                		super.layout(w, h);
                	}
                };

 Thanks


This code is incorrect. first, setExtent is completely meaningless before the invocation of layout, because layout will override whatever extent is already set; second, after you remove the unnecessary setExtent, it becomes just a call to the parent class' layout with the same parameters, which is easier achieved by not overriding anything at all.

 

The proper way of doing it is as follows (suppose you have the maximum width you are willing to allow in a myMaxWidth variable and the height in myMaxHeight):

protected void layout(int maxWidth, int maxHeight) {
  super.layout(Math.min(maxWidth, myMaxWidth), Math.min(maxHeight, myMaxHeight));
}

 

----------------------------------------------------------
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.
Developer
pankajace12
Posts: 188
Registered: ‎04-30-2011
My Carrier: Airtel

Re: Draw rectangle on the background of label

Hi arkadyz

Thanks, I will keep in mind.
Please use plain text.
Regular Contributor
techie
Posts: 77
Registered: ‎05-21-2012

Re: Draw rectangle on the background of label

Thanks so much arkadyz and pankajace12

It worked.

Really appreciate your efforts in guiding me.

Is there any way to add a newline to editfield as the box is not coming in line with the editfield.

 

Please refer the code 

 

                    

HorizontalFieldManager hfm = new HorizontalFieldManager();
       LabelField lbl = new LabelField("\n Name:                  ");
     //As you can see a newline has been added to the name.As the result it goes one level down on the form.But the editfied doesnt.Is there any way to add newline to editfield like String str=" " or something
 
       final EditField TextField1 = new EditField()
       {
           
            protected void layout(int maxWidth, int maxHeight) 
            {
                super.layout(Math.min(maxWidth, 300), Math.min(maxHeight, 20));
            }
           protected boolean keyChar(char ch, int status, int time) 
                {
                if (CharacterUtilities.isLetter(ch) || (ch == Characters.BACKSPACE || (ch == Characters.SPACE))) 
                {
                return super.keyChar(ch, status, time);
                }
               return true;
                }
                
        };
       TextField1.setBorder(BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5)));
       hfm.add(lbl);
       
       hfm.add(TextField1);
       add(hfm);

 

Please use plain text.
Regular Contributor
techie
Posts: 77
Registered: ‎05-21-2012

Re: Draw rectangle on the background of label

Guys i have resolved my problem.Thanks again.It has taken me months in finding out an ideal way to implement.Today finally with your guidance i have done it. :smileyhappy:

Thanks a ton!!! 1m+likes for your post :smileywink:

Please use plain text.