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
NitinPatel
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified
Accepted Solution

How to change default Font size of Basic Edit Field

 

Hi

 

How can I change the default font of the basic EditField?

It should be really easy but I cant figure it out.

I can easily change the font of LabelField using paint mathod but I is not working with BasicEditField.

 

BasicEditField txtTitel = new BasicEditField("", "", 50, BasicEditField.FILTER_DEFAULT)
        {
            public int getPreferredHeight()
            {
                return 30;
            }

            public void layout(int width, int height)
            {
                setExtent(width, getPreferredHeight());
                super.layout(width, getPreferredHeight());
            }
                    
            public void paint(Graphics g)
            {
                g.setColor(0x000000);
                g.drawRect(0, 0, 250, 16);
                Font font = Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt);
                g.setFont(font);
                super.paint(g);
            }
        };

 

Regards

Nitin

Please use plain text.
Developer
simon_hain
Posts: 16,017
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to change default Font size of Basic Edit Field

setFont

----------------------------------------------------------
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
patilajayr
Posts: 404
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi

Re: How to change default Font size of Basic Edit Field

Hello,

          You just add font family. mans a

BasicEditField txtTitel = new BasicEditField("", "", 50, BasicEditField.FILTER_DEFAULT)
        {
            public int getPreferredHeight()
            {
                return 30;
            }

            public void layout(int width, int height)
            {
                setExtent(width, getPreferredHeight());
                super.layout(width, getPreferredHeight());
            }
                    
            public void paint(Graphics g)
            {
                g.setColor(0x000000);
                g.drawRect(0, 0, 250, 16);
                Font font = Font.getDefault().derive(Font.PLAIN,6,Ui.UNITS_pt);
                g.setFont(font);
                super.paint(g);
            }
        };

 Add follwing code into your constrctor.

 

FontFamily alphaSerifFamily = null;
 try 
{
   alphaSerifFamily = FontFamily.forName("bbalpha serif");
} 
catch (ClassNotFoundException e)
{
   e.printStackTrace();
}		
Font appFont = alphaSerifFamily.getFont(Font.UNDERLINED, 6, Ui.UNITS_pt);
Font appFont1= alphaSerifFamily.getFont(Font.PLAIN, 6, Ui.UNITS_pt);
          txtTitel.setFont(appFont1));
          setFont(appFont1);

 thanks

     ajay

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...
K.S

 

 

Please use plain text.
Developer
NitinPatel
Posts: 107
Registered: ‎10-06-2010
My Device: Not Specified

Re: How to change default Font size of Basic Edit Field

Thanks Ajay,

 

It's working fine.

 

I still dont understand what was wrong with using

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

 as it is working fine with my LabelFields.

Please use plain text.