Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextArea Rotation & WordWrap -- Challenging issue.

 
Sainath Veepuri
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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
 
todd runstein
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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
  • 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.:-)
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic