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
Highlighted
Developer
Posts: 89
Registered: ‎07-03-2009
My Device: Not Specified

Custom RichTextField

Hi all,

 

I am going to custom the RichTextField to show the html strings, I have to overwrite the paint() method and draw text line by line. However, I don't know when the text is going to be out of field region, then I can draw the text left in the new line. How can the RichTextField do that? Does anybody know the solution for this? 

 

Thank you.

Binh Nguyen. 

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

Re: Custom RichTextField

Good luck with this.  You will need to determine exactly what you need to display, the extent of the Field, then use Font.getAdvance(..) to determine what will fit,  You need to break it where it doesn't fit (and you will probably want to break on a separator line a space) and then start the next line.  All a lot of fun.  I'm sure there there is some code out there, but this seems like a difficult choice. 

 

Perhaps something like a BrowserField will help you.  Never used on myself, but I'm sure that you can have a Field that takes the html and processes it for you.

Developer
Posts: 89
Registered: ‎07-03-2009
My Device: Not Specified

Re: Custom RichTextField

Thanks Peter, but BBdeveloper confirmed with me that it requires a html file before adding to BrowserField. I have a lot of html strings, so I have to save each string to a html file, it's really terrible.

Now, I am going with TextField.drawText(), I can catch the position and the length of each line, hope that I can draw text from that informs.

Will let you know soon...

 

Regards.  

Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: Custom RichTextField

[ Edited ]
Just an idea: if your HTML is not too complicated it might be easier to parse it into list of (string, font, color, bgcolor) and pass it to existing ActiveRichTextField field rather than implementing all positioning and painting logic yourself.
Message Edited by SergGr on 08-21-2009 08:08 PM

--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.
Developer
Posts: 89
Registered: ‎07-03-2009
My Device: Not Specified

Re: Custom RichTextField

Yeah, but it cannot solve the <sub> and <sup> tab Smiley Mad
Developer
Posts: 89
Registered: ‎07-03-2009
My Device: Not Specified

Re: Custom RichTextField

Hi all,

 

How can we add a new line to a RichTextField, something like the About page of BB:

 

BlackBerry 9000

smartphone (3G, Wifi)

....

 

Or I have to add a new RichTextField for a new paragraph. I intend to use ListField, but I am afraid that it will be truncated when the string is too long.

 

 

Thank you,

Binh Nguyen

 

Developer
Posts: 89
Registered: ‎07-03-2009
My Device: Not Specified

Re: Custom RichTextField


thanhbinh84 wrote:

Hi all,

 

How can we add a new line to a RichTextField, something like the About page of BB:

 

BlackBerry 9000

smartphone (3G, Wifi)

....

 

Or I have to add a new RichTextField for a new paragraph. I intend to use ListField, but I am afraid that it will be truncated when the string is too long.

 

 

Thank you,

Binh Nguyen

 


I can do it now, just add '/n' to the string where you want to start a new paragraph before adding to the RichTextField. 

 

Regards.