• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wrinting a string vertically

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I would like to write a string vertically (i.e from bottom up instead of from left to right). Is there a way to do it or to rotate a string 90 degrees?
Thanks.
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a string in what? The System.out?
Pretty easy, actually.
Reverse the String, then loop & print, one char on each line.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And now seeing as how this is the Swing/JFC/AWT forum, I assume you want to do it in a GUI
The basic idea is still the same:
Reverse the string, iterate through it adding one char at a time to a stringbuffer. But between the chars put in a newline character. Then output it however you want.
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a rotate method in Graphics2D. If you cast your graphics object to Graphics2D. You can call this method.
 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I appreciate your help, but what i mean was not printing something like:
a
v
a
J
I would like, if possible, to print every character in the same orientation as the string. Yes, I want to make it on GUI, swing preferred.
 
Leonardo Fernandes
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can I cast a string to Graphics2D? How?
Thanks
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you cannot cast a String to Graphics2D.
If you overload the paint method of your component you can use the drawString() method in combination with the rotate method to draw the string you need. So you will probably have to do something like this.

I am not sure if this is exactly what you need, it a made up example. But you will have to do something like it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic