Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   How to underline a string in Java? (http://www.velocityreviews.com/forums/t139267-how-to-underline-a-string-in-java.html)

Bruce Sam 12-15-2004 03:08 AM

How to underline a string in Java?
 
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?


Boudewijn Dijkstra 12-15-2004 09:13 AM

Re: How to underline a string in Java?
 
"Bruce Sam" <persevreman@yahoo.com.cn> schreef in bericht
news:1103080126.191175.246640@z14g2000cwz.googlegr oups.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?


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.



Thomas Kellerer 12-15-2004 09:29 AM

Re: How to underline a string in Java?
 
On 15.12.2004 04:08 Bruce Sam wrote:

> 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 van Rossem 12-15-2004 10:40 AM

Re: How to underline a string in Java?
 
On 15-12-2004 04:08, Bruce Sam wrote:
> 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?
>

Yes there is, see java.awt.font.TextAttribute and
java.text.AttributedString.

Paul.

VisionSet 12-15-2004 12:06 PM

Re: How to underline a string in Java?
 


"Bruce Sam" <persevreman@yahoo.com.cn> wrote in message
news:1103080126.191175.246640@z14g2000cwz.googlegr oups.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



Yamin 12-15-2004 06:33 PM

Re: How to underline a string in Java?
 
I am curious to know where you want to underline the string? That is
what is the output or display you want to see the underline? A String
on its own does not have any attributes like underline or bold or
anything. All it holds are the characters.

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.



All times are GMT. The time now is 08:39 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.