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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Developer
Posts: 137
Registered: ‎06-01-2009
My Device: Not Specified
Accepted Solution

LabelField not able to change font size

Regardless the font size I set, It seems no affect and the font size does not change!!. I can change color but not font. What is wrong in code below ?

 

public class FMHorizSingleCont extends HorizontalFieldManager {

 

private LabelField lbDesc;

 

  public FMHorizSingleCont () {

 

     lbDesc = new LabelField(title, LabelField.USE_ALL_WIDTH){

   // Font font = Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt);

       protected void paint(Graphics g) {
      Font font = Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt);

      g.setFont(font);

      g.setColor(Color.
BLACK);

      invalidate();

      super.paint(g);

     }

 };

 

add(lbDesc);

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: LabelField not able to change font size

Set font below the paint() method.

Like:

lbDesc = new LabelField(title, LabelField.USE_ALL_WIDTH) { protected void paint(Graphics g) { //Font font = Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt); //g.setFont(font); g.setColor(Color.BLACK); invalidate(); super.paint(g); } }; Font font = Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt); lbDesc.setFont(font);

 

Regards

Bikas

 

 

Developer
Developer
Posts: 137
Registered: ‎06-01-2009
My Device: Not Specified

Re: LabelField not able to change font size

It works. Thanks.
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: LabelField not able to change font size

You are welcome. Smiley Happy
Highlighted
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: LabelField not able to change font size

I have only just noted this Thread and wish to correct the code given as the solution. 

 

The paint method given in the solution was as follows:

 

    protected void paint(Graphics g)
    {  
       g.setColor(Color.BLACK);
       invalidate();
       super.paint(g);
    }

 

(I have removed the comments.)

In this case the invalidate() is unnecessary and will cause the Blackberry extra work - it will in fact paint the LabelField a number of times.  invalidate() is an instruction to the system to repaint a Field at some stage in the (near) future.  If you give the system this instruction in paint, then every time you paint the Field you are telling the system to repaint it.  This will go on forever running down the battery on your user's phone. 

 

So this code should really be:

    protected void paint(Graphics g)
    { 
       g.setColor(Color.BLACK);
       super.paint(g);
    }

 

Now the default color is Black, so in fact this be removed also, leaving:

 

    protected void paint(Graphics g)
    {  
       super.paint(g);
    }

 

In which case the entire paint() method can be removed, since it is not doing anything useful.

 

And just for the record, it is good practice, when you change something that might impact other places, to make sure your processing doesn't have side effects.  So for example, if you do need to change the color of some text, try using code like this:

 

    protected void paint(Graphics g)
    { 
int currCol = g.getColor()

try {

       g.setColor(<new color>);
       super.paint(g);

} finally {

g.setColor(currColor);

}
    }