Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6919935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:05:06+00:00 2026-05-27T10:05:06+00:00

I am trying to rotate a graphic, but for some reason it won’t work.

  • 0

I am trying to rotate a graphic, but for some reason it won’t work. I’ve done a lot of research looking in other forums but seem to not be able to fix this issue.

So, this is the bit of my program works.

  1. Takes in a file.
  2. Creates buffered image
  3. Creates graphics2D from the bufferedimage.createGraohics();

A Jlabel is made in a pane, which shows the buffered image.
I then have a method to write text on the image, and a method to save the image.
If I write text, then save, that works fine.
This uses:

graphic2D.drawString("Hello, this is my test.",10,10);

I also see this update the JLabel, so I can see the text on the image.

However, if I create a method with:

graphics2D.rotate(45);

I see absolutely nothing change.

Does anyone have any idea why?

This is my method:

public void actionPerformed(ActionEvent e){     
    graphic2D.rotate(4.5);
    saveImage();
}

Thanks,

    import java.io.File;
import java.awt.image.BufferedImage;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class EditorView implements ActionListener, ChangeListener{

    JFrame editorFrame;
    JPanel container = new JPanel();
    JPanel toolbox = new JPanel();
    JPanel editorPanel = new JPanel();
    JScrollPane editorScrollPane;
    File imageFile;
    BufferedImage bi;
    ImageIcon ii;
    Graphics2D graphic2D;
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 10, 5);

    public EditorView(File file){
        this.imageFile = file;

        try{
        bi = ImageIO.read(imageFile);
        }catch(Exception e){}

        graphic2D = bi.createGraphics();

        createAndShowGUI();

    }


    void createAndShowGUI(){

        editorFrame = new JFrame("Editor");
        editorFrame.setSize(1000,650);  
        container.setLayout(new BoxLayout(container,BoxLayout.Y_AXIS));
        editorFrame.add(container);
        toolbox.setMaximumSize(new Dimension(Integer.MAX_VALUE,50));
        toolbox.setPreferredSize(new Dimension(Integer.MAX_VALUE,50));
        toolbox.setLayout(new GridLayout(2,10));
        JButton rotateLeftBtn = new JButton("Rotate Left");
        toolbox.add(rotateLeftBtn);
        rotateLeftBtn.addActionListener(this);
        toolbox.add(new JButton("Save"));
        toolbox.add(new JButton("Close"));
        toolbox.add(new JButton("Freeform"));
        toolbox.add(new JButton("Colour"));
        toolbox.add(new JButton("Text"));
        toolbox.add(new JButton("Square"));
        toolbox.add(new JButton("Circle"));
        toolbox.add(new JButton("Elipse"));
        toolbox.add(new JButton("Rotate Right"));


        slider.addChangeListener(this);
        toolbox.add(slider);


        container.add(toolbox);

        editorScrollPane = new JScrollPane(new JLabel(new ImageIcon(bi)));

        container.add(editorScrollPane);
        editorFrame.setVisible(true);
        editorFrame.validate();
        container.validate();
        editorPanel.validate();

        drawLabel();
        //editorScrollPane.repaint();
    }

    void drawLabel(){
        graphic2D.rotate(1);
        graphic2D.drawString("Hello, this is my test.",10,10);

    }

    void drawCircle(){

    }

    void saveImage(){

        try{
        ImageIO.write(bi,getFileExtension(), imageFile);
        }catch(Exception e){}
    }

    String getFileExtension(){
        int positionOfDot = imageFile.getName().lastIndexOf(".");
        String returner = null;
        if( positionOfDot !=-1){
            returner = imageFile.getName().substring((positionOfDot+1), imageFile.getName().length());
        }
        System.out.println(returner);
        return returner;
    }

    public void actionPerformed(ActionEvent e){ 

        graphic2D.rotate(1);
        saveImage();

    }

    public void stateChanged(ChangeEvent c){
        graphic2D.scale(slider.getValue()/5, slider.getValue()/5);
        editorScrollPane.repaint();

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:05:06+00:00Added an answer on May 27, 2026 at 10:05 am

    The graphics2D.rotate call transforms subsequent renderings, so you need to repaint and put the rotate call just before you render the text.

    See also: Javadocs

    Also, the method requires the input to be in radians.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rotate image single round from it's center point but I
I'm trying to rotate a node around a custom center point in Ogre3D, but
I'm trying to rotate an SVG <polygon> (or any other element) using this: var
I am trying to rotate some images. Works great except I get a strange
I'm trying to rotate an image, but it's getting slightly messed up when I'm
I am trying to design an asic graphics processor. I have done extensive research
I am trying to rotate an image in Java, but when I do the
i am trying to rotate the log file everyday by using the DailyRollingFileAppender, but
I am trying to rotate text on a background-image but my background image is
I'm trying to rotate a needle on a speedometer by looking for each click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.