How to underline a string in Java?

Discussion in 'Java' started by Bruce Sam, Dec 15, 2004.

  1. Bruce Sam

    Bruce Sam Guest

    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?
    Bruce Sam, Dec 15, 2004
    #1
    1. Advertising

  2. "Bruce Sam" <> schreef in bericht
    news:...
    >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.
    Boudewijn Dijkstra, Dec 15, 2004
    #2
    1. Advertising

  3. 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
    Thomas Kellerer, Dec 15, 2004
    #3
  4. 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.
    Paul van Rossem, Dec 15, 2004
    #4
  5. Bruce Sam

    VisionSet Guest

    "Bruce Sam" <> wrote in message
    news:...
    > 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
    VisionSet, Dec 15, 2004
    #5
  6. Bruce Sam

    Yamin Guest

    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.
    Yamin, Dec 15, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sunil
    Replies:
    1
    Views:
    417
    Nicolas LeBlanc
    Jul 15, 2003
  2. Jag
    Replies:
    2
    Views:
    8,381
    Randy Rahbar
    Nov 14, 2003
  3. Music Lover

    Bold Italic UnderLine in TextBox

    Music Lover, Nov 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    812
    Teemu Keiski
    Nov 26, 2003
  4. ALok Gupta via .NET 247
    Replies:
    2
    Views:
    1,106
    John Saunders
    Aug 9, 2004
  5. KatB
    Replies:
    4
    Views:
    18,989
    prashant205
    Aug 24, 2007
Loading...

Share This Page