Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

graphics problem!

 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , i am facing triouble with a small grpahics problem. my project draws liens between various nodes. then a string is printed on these edges. the problem is g.drawString() writes the string completly horizontally. i want the string to be printed neatly next to the edge. u understand what i mean. how can i do this. i know the graphics 2d library has affine transformation, but i dont know how i can do it. thanks for u'r help

the String
------------------------------
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really need to see some code on that in order to help.
 
Mateen Dar
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Graphics2D g1= (Graphics2D)g;
AffineTransform transform=new AffineTransform();
g1.drawLine(10,10,130,130);
transform.rotate(Math.toRadians(45),77,77);
g1.setTransform(transform);
g1.drawString("Hello",75,75);

this piece code does the trick .. but how do i undo the transform. cuase i have other strings to be printed at a different angle. thanks.
 
Ryan McGuire
Ranch Hand
Posts: 1057
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Save the current transform before setting to the rotated one, and then set it back to the saved one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic