• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

\n with drawString()

 
Sam
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does "\n" (carriage return) works with g.drawString() method?
I have tried and found , its not working ? Lets say if I have
to draw a string on the applet in a loop line after line , how will I ? Can somebody Tell me. I tried this line in a loop which is not working :
g.drawString("Something\n",100,100);
thanx in advance.
Regards,
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work because the drawString method is not text based (like a terminal or word processor). It simply duplicates the fonts using pixel, etc. in the Graphics object. The only way to get a new line is to write out the next line using another drawString call and a new 'y' coordinate. Sometimes you'll see stuff like this.

I hope this helps.
Sean
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
The answer given by Sean is very good. I hope it helped you solve your problem.
Next time, please be sure to register with a proper name. "Sam" does not follow the conventions. See here for details: http://www.javaranch.com/name.jsp
If you do not register properly, your account will be disabled. I would hate to see that happen.
Thank you.
Stephanie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic