Click to See Complete Forum and Search --> : Graphics + writing text at angle
boroski
02-26-2004, 08:03 AM
Hi,
Does anyone know how to implement :
g.drawString(....);
so that the string is drawn at an angle eg 30deg
cheers
cjard
02-26-2004, 01:50 PM
niiiice question.. havent got a clue, tbh, but i doubt that it would be simple.. you might have to drawstring to an off-screen buffer, then rotate that image, and paint it in...
someone else has tried it, have a look at this:
http://www.risner.org/java/rotate_text.html
cjard
02-26-2004, 01:51 PM
and another way, if java 1.2 or greater is used, is to play with Graphics2D.. note that rotate() rotates everything!
read this doc:
http://www.ictp.trieste.it/~manuals/programming/Java/tutorial/2d/problems/
(search for "rotate" and read the section
Sir Sapo
02-29-2004, 12:33 AM
Ok i have never tried this but I've seen it done before,
you are going to have to import java.awt.font.* and then use Graphics2D to draw the angled text. Use the .drawString method to write the text, then on a new line, use write g2d.rotate(Math.PI/2.0);
That will rotate the text by 90 degrees, if you want to rotate it by a different amount of degrees, just replace the Math.PI/2.0 with your amount of degrees.
If it works, let me know please.
cjard
02-29-2004, 06:39 PM
Originally posted by Sir Sapo
just replace the Math.PI/2.0 with your amount of degrees.
If it works, let me know please.
specifically, it shouldnt work, because java deals in radians, so a rotate of 75 degrees, following the advice of "just replace math.pi/2.0 with your number of degrees":
g2d.rotate(75);
will not work.. thats a rotation of 75 rads.. very different to degrees... to convert to radians, its:
DEGREES * PI/180
because there are 2 * PI radians in a circle.. so:
75/360 * 2 * PI => 75/180 * PI (seventyfive threesixty'ths of a 2pi circle)
devx.com
Copyright Internet.com Inc. All Rights Reserved