-
Bug
-
Resolution: Won't Fix
-
P3
-
6, 6u10, 7
-
generic, x86
-
generic, windows_xp
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2186318 | 6-pool | Robert Mckenna | P2 | Closed | Cannot Reproduce |
When implementing visual effects with Swing
it's often necessary to paint a component to an off-screen buffer
unfortunately it causes problems if this component or any of its children
are double-buffered
Run the following test and see the unexpected visual artefacts
JDK 6u10 or previous version
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Test {
private static void createGui() {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// panel is double buffered
final JPanel panel = new JPanel();
panel.setSize(100, 100);
JButton b = new JButton("Test") {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Note - the panel is not added to the frame
BufferedImage im = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
panel.paint(im.getGraphics());
}
};
frame.add(b);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Test.createGui();
}
});
}
}
it's often necessary to paint a component to an off-screen buffer
unfortunately it causes problems if this component or any of its children
are double-buffered
Run the following test and see the unexpected visual artefacts
JDK 6u10 or previous version
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Test {
private static void createGui() {
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// panel is double buffered
final JPanel panel = new JPanel();
panel.setSize(100, 100);
JButton b = new JButton("Test") {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
// Note - the panel is not added to the frame
BufferedImage im = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
panel.paint(im.getGraphics());
}
};
frame.add(b);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Test.createGui();
}
});
}
}
- backported by
-
JDK-2186318 Painting a component to an off-screen image should not affect the double buffer
-
- Closed
-
- duplicates
-
JDK-6542106 When a Swing component is painted to an image, it should not go through BufferStrategyPaintManager
-
- Closed
-
-
JDK-6542109 Clean up Swing painting to non-screen graphics.
-
- Closed
-
-
JDK-2148161 When a Swing component is painted to an image, it should not go through BufferStrategyPaintManager
-
- Closed
-
- relates to
-
JDK-6683775 Painting artifacts is seen when panel is made setOpaque(false) for a translucent window
-
- Closed
-