I'm running the following code under JDK 6.0 on Vista. The second line of text
is painted all garbled. The interesting thing here is that all three lines
marked with the comments must be there:
1. Desktop hints must be installed
2. Another text must be painted under the default composite
3. A custom translucent SRC_OVER composite must be installed afterwards
[code]
public class TextRenderingBug extends JPanel {
@Override
protected void paintComponent(Graphics g) {
Graphics2D graphics = (Graphics2D) g.create();
// get the desktop hints and install them
Toolkit toolkit = Toolkit.getDefaultToolkit();
Map desktopHints = (Map) toolkit
.getDesktopProperty("awt.font.desktophints");
if (desktopHints != null) {
// if this line is removed, everything is OK
graphics.addRenderingHints(desktopHints);
}
graphics.setColor(Color.black);
// if this line is removed, everything is OK
graphics.drawString("test", 10, 50);
// if this line is removed, everything is OK
graphics.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 0.6f));
graphics.drawString("test", 10, 80);
graphics.dispose();
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame fr = new JFrame("cool");
fr.setLayout(new BorderLayout());
fr.setSize(400, 300);
fr.add(new TextRenderingBug(),
BorderLayout.CENTER);
fr.setLocationRelativeTo(null);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fr.setVisible(true);
}
});
}
}
[/code]
Any insight on this particular scenario?
Thanks
Kirill
[Message sent by forum member 'kirillcool' (kirillcool)]
http://forums.java.net/jive/thread.jspa?messageID=224990
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".