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
Posts: 115
Registered: ‎10-24-2009
My Device: Not Specified

How to set the colour for Text in the Rich Text feild

[ Edited ]

Hi ll

can i get some example how to change the colour of the text that is displayed through rich textfield or lable Feild please help me ????

Now the text color by default it is in Black color but i want to display the text in White color

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: How to set the colour for Text in the Rich Text feild

LabelField is easy - just override paint(), set the desired foreground color, and call super.paint()

 

RichTextField is more complicated. The colors for text are kept in an array, which corresponds to another array which locates the colored text region offset. This field is faily unusable "as is" - we had to create a wrapper that allows you to "addText" with a foreground color, background color, and font. It's a non-trivial effort, so use the LabelField if this works for you.

 

 

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to set the colour for Text in the Rich Text feild

Supporting Rex explaination, give a look at this KB article.

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

 

If you ahve already solved the issue, you could mark it as solved, it will help other users to know the solution.


Use Search. "Accept Solution" If the problem is resolved.
Highlighted
Developer
Posts: 82
Registered: ‎12-16-2010
My Device: BlackBerry Storm 9950

Re: How to set the colour for Text in the Rich Text feild

[ Edited ]

 

super();
String str[] = new String[] {"Bob", "Bob2"};
int off[] = new int[] {0, str[0].length(), str[0].length() + str[1].length()};
byte attr[] = new byte[] {0, 1};
FontFamily fontfam[] = FontFamily.getFontFamilies();
Font fon[] = new Font[2];
fon[0] = fontfam[0].getFont(FontFamily.SCALABLE_FONT, 48);
fon[1] = fontfam[1].getFont(FontFamily.SCALABLE_FONT, 0);
add(new RichTextField(str[0] + str[1], off, attr, fon, RichTextField.TEXT_ALIGN_HCENTER));
String ramble = new String ("Ipsum Latinracka" +
				
add(new RichTextField(ramble, RichTextField.TEXT_ALIGN_HCENTER));

 

To get Bob, Bob2, and String ramble to appear in white, where in this coding would I insert this:

 

public void paint(Graphics graphics)
    {
        graphics.setColor(0x00008800);
        super.paint(graphics);
    }