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

Posted on 2006-05-24
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
    LVL 6

    Accepted Solution

    Looking at the api documentation at

    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..
    LVL 6

    Expert Comment

    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)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now