FULL PRODUCT VERSION :
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.5
EXTRA RELEVANT SYSTEM CONFIGURATION :
Mid-2012 15" MacBook Pro and Mid-2012 13" MacBook Air
A DESCRIPTION OF THE PROBLEM :
When drawing text using Graphics2D.drawString at an angle in a JComponent by using AffinteTranform to apply a rotation, the text renders incorrectly. The baseline of the text rotates in the opposite direction from the specified angle, while the individual characters counter-rotate in the correct direction. At an angle of zero radians, the text renders correctly. It also renders correctly at Pi radians. At all other angles, it does not render correctly.
REGRESSION. Last worked in version 6u43
REGRESSION : Additional Information
The bug also existed under Apple's version of Java 1.6. However, in that JVM, the bug only existed when using the call
When using Apple's look-and-feel, the bug did not exist. On JDK 1.7 with Oracle's implementation, the bug exists regardless of selected look-and-feel.
The bug did not appear in Apple's JVM 1.5 or earlier.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The test program always produces the incorrrectly rendered text.
EXPECTED VERSUS ACTUAL BEHAVIOR :
In the test program, I expect the text and the line to be in alignment. The text should be centered on the line with the text proceeding radially outwards as if were a strike-through.
In actuality, the baseline of the text rotates in the opposite direction as the specified angle, while the individual letters counter-rotate the correct direction. For angles other than 0, pi/2, pi, and pi*3/4, the letters no longer share a common baseline. For pi/2 and pi*3/4 radians, the text actually renders backwards (in reverse order, (not mirror image).
I can supply a screen shot of the behavior if that would be helpful.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no errors produced, just incorrect rendering of the text.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class AffineTest extends JComponent
public AffineTest ()
setPreferredSize(new Dimension (200, 200));
JFrame frame = new JFrame ("Affine Test");
frame.getContentPane().add (this, BorderLayout.CENTER);
protected void paintComponent (Graphics _g)
int w, h;
g2 = (Graphics2D)_g;
w = getWidth ();
h = getHeight ();
g2.fillRect (0, 0, w, h);
for (angle=0.0; angle<360.0; angle += 45.0)
at = g2.getTransform();
// text and line segment should be in alignment - they are not
g2.drawLine(0, 0, (w/2-10), 0);
g2.drawString ("Test", w/4, 5);
public static void main (String  _args)
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have not found a workaround.