Use the GraphicsDevice object to determine if transparency is supported - Java 2D Graphics

Java examples for 2D Graphics:GraphicsDevice

Description

Use the GraphicsDevice object to determine if transparency is supported

Demo Code

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

public class Main {

  public static void main(String[] args) {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphicsDevice = graphicsEnvironment.getDefaultScreenDevice();

    if (!graphicsDevice.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {
      System.err.println("Translucency is not supported on this platform");
      System.exit(0);/*from  w w  w .j a va  2  s  .c o  m*/
    }
  }
}

GraphicsDevice.WindowTranslucency enumeration represents the types of transparency that may be supported by the platform.

Its values are summarized in the following table.

The alpha value refers to the level of transparency:

Value Meaning
PERPIXEL_TRANSLUCENTRepresents the system support for some of the pixels to be set with potentially different alpha values
PERPIXEL_TRANSPARENTRepresents the system support for all of the pixels to be set to either 0.0f or 1.0f
TRANSLUCENTRepresents the system support for all of the pixels to be set with an alpha value

Related Tutorials