JDK 6 |
---|
6-poolResolved |
Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
|
Relates :
|
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(); } }); } }
|