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
New Developer
Posts: 23
Registered: ‎12-29-2008
My Device: Not Specified

Word Wrap

Hey all,

 

I am currently doing some overcomplicated stuff to get word wrap to work using the Graphics.drawText function where I use the font.getAdvance function in a loop, character by character to see if the text hits the end of a line, break the line and add a hyphen  or elipses if it's between a word or the end of my last line.

 

Is there ANY easier way using maybe a Label field with a transparent background or some other type of object with word wrapping built in?

 

Thanks guys

-paul

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

Re: Word Wrap

What is the reason for not using one of the RichText controls?
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Word Wrap

Hello, Paul.

 

AFAIK there is no easier way instead of checking display width against width of a particular string with current font settings.

New Developer
Posts: 23
Registered: ‎12-29-2008
My Device: Not Specified

Re: Word Wrap

I am overriding the paint function and am not sure how to use the rich text controls in that scenario.  plus, are the rich text controls easily styled?  I have a very specific style I am going for that works with a .png background and the BBAlpha Sans font.

 

To override paint and also have normal added controls would I just call super.paint(Graphics g) at the end of my paint function?

 

once again, sorry if it's n00b :-/

 

-paul

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

Re: Word Wrap

The font is no problem on a RichText control - you can set fonts and colors for various regions of the text, or for the entire text.

 

Regarding the background, are you painting a PNG as the background of a text field?

 

I've been down your path (I think!) and I wound up using the Manager to set/paint the background, then used the text field controls "as is". The reason was that I could not adequately duplicate all of the focus/text selection/wrapping issues with paint() overrides. The paint() events are delegated down through the components from Screen to Manager to Field, so this works out for me (ymmv).