File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JTextArea Rotation & WordWrap -- Challenging issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextArea Rotation & WordWrap -- Challenging issue." Watch "JTextArea Rotation & WordWrap -- Challenging issue." New topic
Author

JTextArea Rotation & WordWrap -- Challenging issue.

Sainath Veepuri
Ranch Hand

Joined: Sep 25, 2003
Posts: 49
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

Joined: Feb 15, 2005
Posts: 64
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

Joined: Sep 25, 2003
Posts: 49
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

Joined: Sep 20, 2005
Posts: 863
    
    1
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.



bitguru blog
Sainath Veepuri
Ranch Hand

Joined: Sep 25, 2003
Posts: 49
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.
 
subject: JTextArea Rotation & WordWrap -- Challenging issue.