|
1 /* @test |
|
2 @bug 6683775 6794764 |
|
3 @summary Painting artifacts is seen when panel is made setOpaque(false) for a translucent window |
|
4 @author Alexander Potochkin |
|
5 @run main bug6683775 |
|
6 */ |
|
7 |
|
8 import com.sun.awt.AWTUtilities; |
|
9 import sun.awt.SunToolkit; |
|
10 |
|
11 import javax.swing.*; |
|
12 import java.awt.*; |
|
13 import java.awt.image.BufferedImage; |
|
14 |
|
15 public class bug6683775 { |
|
16 public static void main(String[] args) throws Exception { |
|
17 GraphicsConfiguration gc = getGC(); |
|
18 if (!AWTUtilities.isTranslucencySupported( |
|
19 AWTUtilities.Translucency.PERPIXEL_TRANSLUCENT) |
|
20 || gc == null) { |
|
21 return; |
|
22 } |
|
23 SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
|
24 Robot robot = new Robot(); |
|
25 final JFrame testFrame = new JFrame(gc); |
|
26 |
|
27 SwingUtilities.invokeLater(new Runnable() { |
|
28 public void run() { |
|
29 JFrame backgroundFrame = new JFrame("Background frame"); |
|
30 backgroundFrame.setUndecorated(true); |
|
31 JPanel panel = new JPanel(); |
|
32 panel.setBackground(Color.RED); |
|
33 backgroundFrame.add(panel); |
|
34 backgroundFrame.setSize(200, 200); |
|
35 backgroundFrame.setVisible(true); |
|
36 |
|
37 testFrame.setUndecorated(true); |
|
38 JPanel p = new JPanel(); |
|
39 p.setOpaque(false); |
|
40 testFrame.add(p); |
|
41 AWTUtilities.setWindowOpaque(testFrame, false); |
|
42 testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
43 testFrame.setSize(400, 400); |
|
44 testFrame.setLocation(0, 0); |
|
45 testFrame.setVisible(true); |
|
46 } |
|
47 }); |
|
48 |
|
49 toolkit.realSync(); |
|
50 |
|
51 //robot.getPixelColor() didn't work right for some reason |
|
52 BufferedImage capture = robot.createScreenCapture(new Rectangle(100, 100)); |
|
53 |
|
54 int redRGB = Color.RED.getRGB(); |
|
55 if (redRGB != capture.getRGB(10, 10)) { |
|
56 throw new RuntimeException("Transparent frame is not transparent!"); |
|
57 } |
|
58 } |
|
59 |
|
60 private static GraphicsConfiguration getGC() { |
|
61 GraphicsConfiguration transparencyCapableGC = |
|
62 GraphicsEnvironment.getLocalGraphicsEnvironment() |
|
63 .getDefaultScreenDevice().getDefaultConfiguration(); |
|
64 if (!AWTUtilities.isTranslucencyCapable(transparencyCapableGC)) { |
|
65 transparencyCapableGC = null; |
|
66 |
|
67 GraphicsEnvironment env = |
|
68 GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
69 GraphicsDevice[] devices = env.getScreenDevices(); |
|
70 |
|
71 for (int i = 0; i < devices.length && transparencyCapableGC == null; i++) { |
|
72 GraphicsConfiguration[] configs = devices[i].getConfigurations(); |
|
73 for (int j = 0; j < configs.length && transparencyCapableGC == null; j++) { |
|
74 if (AWTUtilities.isTranslucencyCapable(configs[j])) { |
|
75 transparencyCapableGC = configs[j]; |
|
76 } |
|
77 } |
|
78 } |
|
79 } |
|
80 return transparencyCapableGC; |
|
81 } |
|
82 } |