If the API would support underlining, then directly drawing a line isn't a
good way. But it isn't supported.
Use java.awt.Font#getBaselineFor(char) to position your line correctly.
> I thinked direct draw a line is not a good way.Also,I don't need the
> method of using HTML to implement this.Are there a good method to
> underline a string in java?
>
Where do you display the String? If you use a JLabel you can do the following:
JLabel l = new JLabel("<html><u>This is underlined</u> and this is not</html>");
Thomas
Paul.
"Bruce Sam" <perse...@yahoo.com.cn> wrote in message
news:1103080126.1...@z14g2000cwz.googlegroups.com...
> I thinked direct draw a line is not a good way.Also,I don't need the
> method of using HTML to implement this.Are there a good method to
> underline a string in java?
>
You can probably also do this in unicode using combined diacritical or
whatever they are called. See unicode.org and use there codes like \uxxxx
where xxxx is the hex of there code.
--
Mike W
Is the output just a label? Then the method used by Thomas is the
easiest. I've always liked this method. It makes things really easy
to customize the display.
Is the output a file, then you have to find out what the file format
says about underlining if any.