Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to underline a string in Java?

Reply
Thread Tools

How to underline a string in Java?

 
 
Bruce Sam
Guest
Posts: n/a
 
      12-15-2004
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?

 
Reply With Quote
 
 
 
 
Boudewijn Dijkstra
Guest
Posts: n/a
 
      12-15-2004
"Bruce Sam" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed) 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.


 
Reply With Quote
 
 
 
 
Thomas Kellerer
Guest
Posts: n/a
 
      12-15-2004
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
 
Reply With Quote
 
Paul van Rossem
Guest
Posts: n/a
 
      12-15-2004
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.
 
Reply With Quote
 
VisionSet
Guest
Posts: n/a
 
      12-15-2004


"Bruce Sam" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
Yamin
Guest
Posts: n/a
 
      12-15-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Underline words Joan Microsoft Certification 0 09-09-2003 05:47 PM
sorting and datagrid and underline sunil ASP .Net 1 07-15-2003 09:26 PM
Firebird - html underline probs Thanks AC Firefox 0 06-25-2003 09:01 PM
Re: Firebird - html underline probs Kriss Watt Firefox 0 06-24-2003 11:41 PM
Re: Firebird - html underline probs Gnomalarta Firefox 0 06-24-2003 07:39 PM



Advertisments