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
NiceNix
Posts: 73
Registered: ‎10-23-2009
My Device: Not Specified
Accepted Solution

No Underlined Fonts?

 

        Font f = Font.getDefault();
        Font newf = f.derive(Font.UNDERLINED);
        int fStyle = f.getStyle();
        int newfStyle = newf.getStyle();

        setFont(newf);

 

 

I am trying to get underlined text.  I extend LabelField and use the above code in the constructor.  For all fonts on all the simulators I've tried I get fStyle == 0, newfStyle == 4 (underline), but the displayed text NEVER has an underline.  What am I doing wrong here?

 

I thought of drawing the underline myself, but I don't know ahead of time how many lines of text I am going to have.  I don't want to have to write a line wrapping algorithm just to add underlining.  :-(

 

Any help would be awesome.

 

Thanks,

~NN

Developer
NiceNix
Posts: 73
Registered: ‎10-23-2009
My Device: Not Specified

Re: No Underlined Fonts?

bump.

 

Additional info:

I also override paint() in my customLabelField, but the only thing I do is change the current color and call super.paint().

 

Has anybody else ever been able to get underlining to work in any context outside the BrowserField?

 

Thanks,

~NN

Developer
yosoh
Posts: 213
Registered: ‎07-18-2008
My Device: Not Specified

Re: No Underlined Fonts?

this one works though:

 

 

 

 

LabelField _testLink = new LabelField("My underlined text",  Field.USE_ALL_WIDTH) ;

		 Font licFont = _testLink.getFont().derive(Font.UNDERLINED);
		 _testLink.setFont(licFont);

 

 

 

--------------------------------------------------
problemSolved() ? kudosPlease():kudosPlease();
Developer
NiceNix
Posts: 73
Registered: ‎10-23-2009
My Device: Not Specified

Re: No Underlined Fonts?

Thanks, yosoh.

 

The same code fails to underline the text on my simulators. ... something must have gotten hosed in the actual simulator config.  I'll try delete/reinstall of the simulators and see if it clears up.

Developer
NiceNix
Posts: 73
Registered: ‎10-23-2009
My Device: Not Specified

Re: No Underlined Fonts?

Success!

 

Cleaning the simulator sorted it out enough that yosoh's code worked.  After that I was able to find what I had done wrong in my own code....

 

By setting the font in the constructor, I was actually overwriting the change when I called CustomLabelField.setFont() in the calling code.  :-/ Stupid oversight on my part.  Corrected by overriding setFont() to also derive an underlined font.  Works now.

 

Thanks for help!

~NN