-
Bug
-
Resolution: Fixed
-
P4
-
6
-
b17
-
generic
-
generic
-
Verified
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
----------------
import java.awt.*;
import javax.swing.*;
import java.util.*;
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);
}
});
}
}
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
----------------
import java.awt.*;
import javax.swing.*;
import java.util.*;
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);
}
});
}
}
- relates to
-
JDK-8273685 Remove jtreg tag manual=yesno for java/awt/Graphics/LCDTextAndGraphicsState.java & show test instruction
- Resolved