Escape codes not working

Discussion in 'Java' started by Steve, Jun 21, 2004.

  1. Steve

    Steve Guest

    Hi all,

    Why is it that the statement:

    Label l = new Label("This \n Test should work");

    shows the label with a block (as in, square) character instead of the linefeed?
     
    Steve, Jun 21, 2004
    #1
    1. Advertisements

  2. From the API doc of java.awt.Label:

    "A label displays a single line of read-only text."
     
    Michael Borgwardt, Jun 21, 2004
    #2
    1. Advertisements

  3. Steve

    Fedor Guest

    Have you tried carriage return (\r) or both \n and \r ?


    f
     
    Fedor, Jun 21, 2004
    #3
  4. Because it is not supported. Use a TextArea instead, or use Swing and
    HTML in the label.

    /Thomas
     
    Thomas Weidenfeller, Jun 21, 2004
    #4
  5. Steve

    Roedy Green Guest

    Because Label is not smart enough, or rather the underlying GUI is not
    smart enough. To get that effect you need Swing JLabel and use HTML
    and encode your linefeed as <br>
     
    Roedy Green, Jun 21, 2004
    #5
  6. Steve

    Jacob Guest

    Label is defined to be one line, so this has nothing
    to do with lack of smartness.
    Don't use HTML; Google for "MultiLineLabel" instead.
     
    Jacob, Jun 22, 2004
    #6
  7. Well, if you ask me, it would be a lot smarter for Label to support
    multiline than not to.
    Why, when JLabel already does this anyway? Does MultiLineLabel do
    something that JLabel can not?

    Cheers
    Bent D
     
    Bent C Dalager, Jun 22, 2004
    #7
  8. Steve

    Roedy Green Guest

    But if you ponder WHY Label was defined that way, the reason is the
    that Label is a heavyweight component. It is limited by what
    heavyweight Label components in various GUIs can do. In general, they
    are not smart enough to handle multiline labels. Thus, Java had to
    limit Label to the lowest common denominator.

    In Swing, JLabel is a lightweight component. It thus does not matter
    what the underlying GUI does, so JLabel can even be smart enough to
    render HTML or Images.
     
    Roedy Green, Jun 22, 2004
    #8
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.