Results 1 to 2 of 2
  1. #1
    AvivC is offline Member
    Join Date
    Dec 2013
    Rep Power

    Default How to rotate graphic object and have it stay at it's place?

    I have a class DrawingPanel, extending JPanel and added to a JFrame.

    Java Code:
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    public class DrawingPanel extends JPanel {
    	public void paintComponent(Graphics g){
    		Graphics2D g2d = (Graphics2D)g;
    		g2d.setFont(new Font("Arial",Font.BOLD,24));
    		g2d.rotate(30 * Math.PI/180);
    "B" is not only rotated 30 degrees, but also apears in a far different location than "A".

    I think I understand why that is. It's because rotating and scaling means rotating and scaling the entire x and y system too, or something like that.

    But my question is, how could I rotate a graphic object, and have it stay at the place that it "was" before I rotated it? (Or before I scaled it, got the same problem there).

    Thanks :)
    Last edited by AvivC; 12-31-2013 at 09:55 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: How to rotate graphic object and have it stay at it's place?

    When you rotate an object, you rotate it around a fixed point, or the center of rotation. So if you draw a square and want to rotate it, you need to translate the center of rotation to the center of the square.

    Last edited by jim829; 12-31-2013 at 11:13 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. GridBagLayout - forcing all components to stay on top
    By Serpenthelm in forum AWT / Swing
    Replies: 3
    Last Post: 01-05-2012, 06:52 PM
  2. Trying to display a copied Graphic object - SSCCE
    By AcousticBruce in forum New To Java
    Replies: 11
    Last Post: 03-03-2011, 03:18 AM
  3. Forcing the mouse to stay quiet
    By ProspectiveDeveloper in forum AWT / Swing
    Replies: 4
    Last Post: 05-02-2010, 11:17 PM
  4. Replies: 5
    Last Post: 04-25-2009, 08:00 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts