File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "printing multiple line string" Watch "printing multiple line string" New topic

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"

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.

"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" +
what class would allow me to to something like this
thank u
I agree. Here's the link:
subject: printing multiple line string
It's not a secret anymore!