• 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

JTextArea Rotation & WordWrap -- Challenging issue.

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

My aim is to rotate the text on a JTextarea. With the below code I could do the rotation. But now the problem is that I'am unable to set wordwrapping on the same as I have overriden the paintComponent method. It just puts everything in one line.

String sText = "I have changed your graphics. How can I set the wordwrapping on you ?";

JTextArea jTextArea = new JTextArea(){
public void paintComponent(Graphics g) {

super.paintComponent(g);

Graphics2D g2d = (Graphics2D) g;
g2d.translate( getWidth()/2, getHeight() );
g2d.rotate( Math.toRadians(270) );

g2d.drawString(sText, 0, 0);

}
};

We have got a release and I'am stuck with this.
Any suggestions would be greatly helpful.

Thankyou,
Sainath Veepuri
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ouch. You're going to need to break the lines and do the wrapping yourself. You should be able to use a LineBreakMeasurer to determine where to break each line. Instead of drawing strings, you'll be working with TextLayout objects. It's a bit more work, but you'll have all the flexibility you need.

Take a look at the Java2D tutorial on text: http://java.sun.com/developer/onlineTraining/Media/2DText/style.html
 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi todd runstein,
Thanks a bunch for your suggestion
I was worried since no one was responding to my query even in the sun forum
web page

I'am amazed to see your response.
Yes, I will try that out by reading the link.
Thanks to javaranch,
Thanks to you again,
Sai.:-)
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's challenging to do this "right" but it's
not so tough to do something quick and dirty
that can break lines on its own.

 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brian Cole,
Thank you.
Your code simply has made my life much easier. It works!
I never thought it was so easy.
Thankyou again,
Sai.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic