Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printing multiple line string

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic