Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By JosAH
  • 1 Post By Norm

Thread: New line in Strings

  1. #1
    Josep_16's Avatar
    Josep_16 is offline Member
    Join Date
    Mar 2011
    Posts
    40
    Rep Power
    0

    Default New line in Strings

    Hi there. I was trying to add line separators to a String in my JApplet, but it seems to not work.

    Just after defining the class, I define the "newline" variable:

    Java Code:
    static final String newline = System.getProperty("line.separator");
    The code of the String is the next one:

    Java Code:
    String strNegativeRectangle = (
                                                "Fr = "
                                                +strFr
                                                +newline
                                                +"Em = "
                                                +strEm);
    
    g2.drawString(strNegativeRectangle,10,10);

    So, it should look like:

    Fr = strFr
    Em = strEm


    But it looks like:

    Fr = strFrEm = strEm



    Well, where's the error ? :S
    Thanks and regards.
    Last edited by Josep_16; 09-07-2011 at 10:15 AM.

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default Re: New line in Strings

    use the "\\n" for line separator in string
    sanjeev,संजीव

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: New line in Strings

    Quote Originally Posted by sanjeevtarar View Post
    use the "\\n" for line separator in string
    Have you tested that suggestion? It won't work, the drawString( ... ) method can't draw newline characters.

    kind regards,

    Jos
    Josep_16 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: New line in Strings

    You need to change the y value and call drawString again for each new position you want to draw a String on.
    Josep_16 likes this.

Similar Threads

  1. How to make new-line when p rinting strings?
    By ozzyman in forum Java 2D
    Replies: 2
    Last Post: 05-04-2011, 09:24 AM
  2. Replies: 1
    Last Post: 02-13-2011, 03:09 PM
  3. tracing java application line by line using netbeans
    By chandrasekhar123 in forum NetBeans
    Replies: 1
    Last Post: 08-03-2010, 02:46 PM
  4. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  5. Replies: 4
    Last Post: 09-10-2009, 10:18 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
  •