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
New Developer
Posts: 9
Registered: ‎12-19-2011
My Device: 9300
My Carrier: MTN
Accepted Solution

how to apply different fonts to the text(words) on the same field

please help, how to apply different fonts to the text(words) on the same field. i want to select text and apply font, size and color on that selected text in the field, this code below, setFont method changes the whole text in a field(message) to a select the font. please help

 

        message = new AutoTextEditField("","",maxNumChars,editableStyle)
        {
            protected void layout(int width, int height) 
            {
                super.layout(width, height);
                this.setExtent(550, 250);
            }       
        };
        message.setBorder(border);
        message.setMargin(xyEdgeForMargin);
        message.setPadding(xyEdgeForPadding);
        message.setFont(_menuFont);

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to apply different fonts to the text(words) on the same field

New Developer
Posts: 9
Registered: ‎12-19-2011
My Device: 9300
My Carrier: MTN

Re: how to apply different fonts to the text(words) on the same field

thanks alot Peter. the RichTextField is a read-only field. Maybe i should have been more specific. I want to apply different fonts on an editable field like AutoTextEditField or TextEditField. Where the user can type the 1st sentance with defualt font and type the 2nd sentance with a different font, size and color - (example).They will use dropdowns to change font types.

Highlighted
Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: how to apply different fonts to the text(words) on the same field

There is no editable field available in blackberry jde which supports different fonts, if you want to use this type of field, you would need to customize this by your own, you would need to override paint method of the field.

New Developer
Posts: 9
Registered: ‎12-19-2011
My Device: 9300
My Carrier: MTN

Re: how to apply different fonts to the text(words) on the same field

thanks alot. any code snip to get me started maybe, still new on this field of blackberry development.

Developer
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: how to apply different fonts to the text(words) on the same field

Just write your edit field as

 

public class RichEditField extends BasicEditFields

{

int[] offsets=null;

Font[] font= null;

String text=null;

RichEditField(String label, String text, int[] offsets, Font[] font)

{

   super(label, text);

   this.text=text;

   this.label=label;

   this.offsets=offsets;

   this.font=font;

   // add Some validation here for offsets and text

}

 

RichEditField(String label, String text)

{

   super(label, text);

   this.text=text;

   this.label=label;

   this.offsets={0};

   this.font={g.getDefaultFont()};

   // add Some validation here for offsets and text

}

/*Here are some method to add customization of fonts like

setFont(offset, length);

setFont(offset);

public void paint(Graphics g)

{

g,clear();

        for(int i=0;i<offsets.length;i++)

{

//calculate next x, y by using offset

int length=0;

 

g.setFont(font[i]);

if(i<offset.length-1)

length=offset[i+1]-offset[i];

else

length=text.length()-offset[i];

g.drawText(text.substring(0, length), x, y);

super.paint(g);

 

}

}

 

this method is not compiled so may have errors, and may have many features according to your requirements.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to apply different fonts to the text(words) on the same field

Remember also that drawText does not do word wrap for you - it writes everything on the same line.  So you can write off the end of the screen.  You will need to word wrap this yourself.  You may be able to find suitable code if you search the forum, various Threads have discussed word wrap.