01-12-2010 11:16 AM
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.
Solved! Go to Solution.
01-14-2010 09:37 AM
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?
01-14-2010 10:01 AM
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);
01-14-2010 10:38 AM
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.
01-14-2010 11:04 AM
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!