Learn how to a build a cloud-first strategyRegister Now


java2D reverse text with g2d.transform(AffineTransform.getScaleInstance(-1, 1)) doesn't work

Posted on 2006-05-24
Medium Priority
Last Modified: 2008-02-20
I am trying to build a graphic with text "mirrored", going from right to left
(with the letters backwards too). To test, I am using:

                  g2d.transform(AffineTransform.getScaleInstance(-1, 1));
                  g2d.drawString("-300,-300", -300, -300);
                  g2d.drawString("-300,0", -300, 0);
                  g2d.drawString("-300,300", -300, 300);
                  g2d.drawString("0,-300", 0, -300);
                  g2d.drawString("0,0", 0, 0);
                  g2d.drawString("0,300", 0, 300);
                  g2d.drawString("300,-300", 300, -300);
                  g2d.drawString("300,0", 300, 0);
                  g2d.drawString("300,300", 300, 300);

but no text shows up anywhere.
if I change the first line to:
                  g2d.transform(AffineTransform.getScaleInstance(1, 1));
it works as expected. Am I doing something wrong, or is this not allowed in java2D?
Question by:lfrohman
  • 2

Accepted Solution

VBGuru earned 1000 total points
ID: 16757917
Looking at the api documentation at http://java.sun.com/j2se/1.3/docs/api/java/awt/geom/AffineTransform.html.

Seems like when you have
AffineTransform.getScaleInstance(-1, 1)) set, you end up with the following coordinates
(300,0), (300,300), (0,-300),(0,0), (0,300),(-300,-300),(-300,0),(-300,300)

while using AffineTransform.getScaleInstance(-1, 1)) you will have following coordinates
(-300, -300),(-300, 0),( -300, 300),( 0, -300),(0, 0),( 0, 300),( 300, -300),( 300, 0)(300, 300)

Hope this explains..

Expert Comment

ID: 16757930
for AffineTransform.getScaleInstance(-1, 1)) set, you end up with the following coordinates
(300,-300),(300,0), (300,300), (0,-300),(0,0), (0,300),(-300,-300),(-300,0),(-300,300)

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question