Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default new line within a string

    Hi, when my applet calls the string to display the description of something, of course it prints out a long line, which is bad because the string is a paragraph long and i want it be in lines. I have played with the + /n + command but it doesnt affect it and prints out the long line still?

    My string is-
    String TentDesc [] = {"blah....................... blah............................... blah"}

    I have tried playing with the + /n + postioning but to no avail?

    Maybe because its in an applet, will i have to somehow loop it to start a line down after so many chars have been printed? Or would it be easier to just fill a text box?

    Any ideas of the best or standard way this is done?

  2. #2
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    btw its a java awt applet, not swing

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,370
    Blog Entries
    1
    Rep Power
    22

  4. #4
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    11

    Default

    Hey perplexingtrax.

    Instead of using /n use this:

    Java Code:
    String newline = System.getProperty("line.separator");
    So your code should look something like this:

    Java Code:
    String newline = System.getProperty("line.separator");
    
    String TentDesc[] = "blah.." + newline + "blah.." + newline + "blah.."
    Sorted ;)

  5. #5
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    Thanks DonCash but that doesn't seem to affect the string when i call paint in the applet, its still a sentence. My string is something like this now-

    String TentDesc [] =
    {"blah....................... blah............................... blah",
    "blah....................... blah............................... blah",
    "blah....................... blah............................... blah",
    };

    its put through actionPerformed in a for loop and given the value
    message =(TentDesc[j]);

    i called it in paint like
    g.drawString(message,900, 100);

    Eranga
    i think i do use them yes

  6. #6
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    i have it now going into a TextField. any idea's how to set the text wrapping in the text box? thanks

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,370
    Blog Entries
    1
    Rep Power
    22

    Default

    If you mean about multiple text lines on a TextFeild I don't think it is possible. You may use TextArea. There you can use multiple lines for text.

  8. #8
    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Default Re: new line within a string

    Do go for <HTML> tags with <BR>...But it could pose for some font change...take care of them

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,314
    Blog Entries
    7
    Rep Power
    25

    Default Re: new line within a string

    This thread doesn't even smell funny anymore; it has been dead for five years. I'm closing it.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. print line
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 01-26-2008, 03:05 PM
  2. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  3. Reading in data from file line by line
    By bluekswing in forum New To Java
    Replies: 1
    Last Post: 10-02-2007, 12:19 AM
  4. Replies: 1
    Last Post: 08-07-2007, 07:29 AM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •