test/java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java
Print this page
*** 35,49 ****
import javax.swing.*;
public class TranslucentJAppletTest {
private static JFrame frame;
private static volatile boolean paintComponentCalled = false;
private static void initAndShowGUI() {
! frame = new JFrame();
JApplet applet = new JApplet();
applet.setBackground(new Color(0, 0, 0, 0));
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
paintComponentCalled = true;
--- 35,50 ----
import javax.swing.*;
public class TranslucentJAppletTest {
+ private static volatile GraphicsConfiguration graphicsConfig = null;
private static JFrame frame;
private static volatile boolean paintComponentCalled = false;
private static void initAndShowGUI() {
! frame = new JFrame(graphicsConfig);
JApplet applet = new JApplet();
applet.setBackground(new Color(0, 0, 0, 0));
JPanel panel = new JPanel() {
protected void paintComponent(Graphics g) {
paintComponentCalled = true;
*** 64,73 ****
--- 65,95 ----
public static void main(String[] args)
throws Exception
{
sun.awt.SunToolkit tk = (sun.awt.SunToolkit)Toolkit.getDefaultToolkit();
+ final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ for (GraphicsDevice gd : ge.getScreenDevices()) {
+ if (gd.isWindowTranslucencySupported(
+ GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSLUCENT))
+ {
+ for (GraphicsConfiguration gc : gd.getConfigurations()) {
+ if (gc.isTranslucencyCapable()) {
+ graphicsConfig = gc;
+ break;
+ }
+ }
+ }
+ if (graphicsConfig != null) {
+ break;
+ }
+ }
+ if (graphicsConfig == null) {
+ System.err.println("The system does not support translucency. Consider the test passed.");
+ return;
+ }
+
Robot r = new Robot();
Color color1 = r.getPixelColor(100, 100); // (0, 0) in frame coordinates
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {