*
The moose likes Java in General and the fly likes printing multiple line string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "printing multiple line string" Watch "printing multiple line string" New topic
Author

printing multiple line string

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
Im trying to print a multiline string Im
using drawString(String s, x, y) and the
string is a multiple line String but yet
when I print it; it comes as a single line
of text. Can someone help
------------------
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
When you use drawString, you are painting something not "printing" it. And Graphics is not a Text based class, and does not understand things like linefeeds.
You could either have a drawString for each line that you want to print (you would need to work out the next lines starting coordinates based on the particular font that you are using), or use a text based class to get the string printed.
What is it exactly that you are trying to accomplish? Could you just use a Label or something like that?
Here is a link that shows how to make a multi line label by sub-classing canvas. http://www1.uni-bremen.de/~wboeck/java/javabook/javabo74.htm


"JavaRanch, where the deer and the Certified play" - David O'Meara
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
I have numerous textfields which are filled by
the user and he has the option to print. So im
trying to sting all the stings together. So I would
like something like this
String s = "text1 \n" +
"text2\n" +
..........."text20\n";
what class would allow me to to something like this
thank u
------------------
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: printing multiple line string
 
Similar Threads
StringTokenizer output formatting
Returning array To Method
404 Error
Help with LineNumber Reader class
How to store the newlines entered by enter key in textarea?