Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

\n with drawString()

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 :
thanx in advance.
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.
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
If you do not register properly, your account will be disabled. I would hate to see that happen.
Thank you.
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic