Problem using AffineTransform
I'm drawing a hexagon in the center of a JPanel. I am then drawing
squares on each side of the polygon. To map the edges of the square onto
the sides of the polygon, I am transforming the co-ordinates of the
squares and rotating them so that their sides map onto the sides of the
polygon. When I try doing this in a JFrame where there's only one
JPanel, everything works fine.. however, when I put this JPanel onto one
side of a JSplitpane (or even if I add another JPAnel onto the JFrame),
the transformed squares fall elsewhere, on the left side of the polygon
when they should actually transform and map onto the sides of the polygon.
It seems that the AffineTransform.getRotateInstance() method is taking
the wrong set of co-ordinates. It is taking the center of the "JFrame"
for some reason. Can anyone please help me identify the problem here?
Why isnt AffineTransform.getRotateInstance() not working properly?
Eventhough I'm giving it the same set of co-ordinates I used for drawing
the polygon (in the center of the JPanel - which seems to work fine), it
just won't transform the squares at the right place. If I comment out
the following line where I am setting the transform object:
The squares are drawn at the correct co-ordinates, except that they
aren't rotated. How can I fix this? thanks a lot!
Re: Problem using AffineTransform
On Wed, 08 Oct 2003 11:27:23 +1000, Rick <rrquick@nospam-com> wrote:
>The squares are drawn at the correct co-ordinates, except that they
>aren't rotated. How can I fix this? thanks a lot!
static AffineTransform getRotateInstance(double theta);
static AffineTransform getRotateInstance(double theta, double x, double
with the second function you can specify the pivot point of the
Seti@Home Java Applets
Re: Problem using AffineTransform
Rick <rrquick@nospam-com> writes:
> polygon. When I try doing this in a JFrame where there's only one
> JPanel, everything works fine.. however, when I put this JPanel onto one
> side of a JSplitpane (or even if I add another JPAnel onto the JFrame),
> the transformed squares fall elsewhere, on the left side of the polygon
> when they should actually transform and map onto the sides of the polygon.
I would guess that one of two things (or both :-)) happens:
1. You get a Graphics that has a different origin (location of (0,0))
than you expect. In fact, you can see rather interesting configurations
of the Graphics object when e.g. a partial redraw of a component should
happen. These configurations are not wrong, just not as simple as one
would like it. Print out all the data of the Graphics object to get
some idea of what might be different.
2. You don't reset the Graphics to the original transformation once you
are done inside one paintComponent(). Swing passes the very same
Graphics object to all the lightweight components down in a component
hierarcy (this is Swing's double buffer mechnism). So if you change the
Graphics object in one component's paintComponent() method the change
might influence the later painting in another component. Get the
Graphic's transformation at the beginning of a paintComponent()
implementation and reset the Graphics to the transformation before you
exit the method.
|All times are GMT. The time now is 12:27 PM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.