Problem using AffineTransform

Discussion in 'Java' started by Rick, Oct 8, 2003.

  1. Rick

    Rick Guest

    Hi,

    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:

    g2.setTransform(rotate45);

    The squares are drawn at the correct co-ordinates, except that they
    aren't rotated. How can I fix this? thanks a lot!

    Cheers

    Rick
     
    Rick, Oct 8, 2003
    #1
    1. Advertising

  2. 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
    y);

    with the second function you can specify the pivot point of the
    rotation.

    HTH,
    ciao
    --
    Seti@Home Java Applets
    http://maruko.webhop.net/
     
    Marco Parmeggiani, Oct 8, 2003
    #2
    1. Advertising

  3. 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.


    HTH

    /Thomas
     
    Thomas Weidenfeller, Oct 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hilz
    Replies:
    2
    Views:
    1,337
  2. SPG
    Replies:
    0
    Views:
    385
  3. news.skynet.be
    Replies:
    0
    Views:
    602
    news.skynet.be
    Mar 25, 2005
  4. fiziwig
    Replies:
    10
    Views:
    2,397
    Thomas Weidenfeller
    Aug 14, 2006
  5. Thijs Muizelaar

    AffineTransform

    Thijs Muizelaar, Jan 11, 2008, in forum: Java
    Replies:
    4
    Views:
    422
    Wayne
    Jan 11, 2008
Loading...

Share This Page