Solved

New Line for text

Posted on 1997-11-14
11
209 Views
Last Modified: 2010-04-16
I am trying to place some text in a applet (e.g., Text = "this is the text") I want to make the text goto the a new line.  I know that I need to use \n, but how do I put it in the string to make it brake to a new line.
0
Comment
Question by:Maurice072297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 4

Expert Comment

by:russgold
ID: 1230620
String text = "this is line 1" + '\n' + "this is line 2";
0
 
LVL 4

Expert Comment

by:russgold
ID: 1230621
Of course, that technique is not portable.  You do better to use something like:

String separator = System.getProperty( "line.separator" );
String text = "this is line 1" + separator + "this is line 2";

which is guaranteed to be portable to all platforms.
0
 

Author Comment

by:Maurice072297
ID: 1230622
This will not work for applets??  only applications correct??
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 4

Expert Comment

by:russgold
ID: 1230623
No, this works for applets, as well.  It is one of the properties that *is* accessible from an applet.
0
 

Author Comment

by:Maurice072297
ID: 1230624
When I use this statement I either get a box or I get a seperator line.  It does not place the second string on a new line.
0
 
LVL 4

Expert Comment

by:russgold
ID: 1230625
Which statement are you using?  Is your applet on the web somewhere for me to try?
0
 

Author Comment

by:Maurice072297
ID: 1230626
I have not put it on the web yet, cause I can't get it to work.  I tried the statement that you gave me, an I also tried

String text;

public void init() {
  text = "This is string 1" + '\n' + "This is string 2"
}
public void paint(Graphics g) {
  g.drawString(text, 20, 50);
}

neither statement works.  both either give me a | or a box.

0
 

Expert Comment

by:maha
ID: 1230627
instead of "\n" try "\r\n"


Maha
0
 

Author Comment

by:Maurice072297
ID: 1230628
That did not work either.
0
 

Accepted Solution

by:
rans earned 20 total points
ID: 1230629
Did you try to use Label instead of direct drawing to screen ?

Label l=new Label("line1 \n line2");
add(l);
0
 

Author Comment

by:Maurice072297
ID: 1230630
I got it to work.  I used a Texarea.  But the way that you suggested also works.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question