Java examples for 2D Graphics:GraphicsDevice
Use the GraphicsDevice object to determine if transparency is supported
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_TRANSLUCENT | Represents the system support for some of the pixels to be set with potentially different alpha values |
PERPIXEL_TRANSPARENT | Represents the system support for all of the pixels to be set to either 0.0f or 1.0f |
TRANSLUCENT | Represents the system support for all of the pixels to be set with an alpha value |