12.3. Device Configurations

A java.awt.GraphicsConfiguration represents a specific setup of a specific graphics device. There are a few interesting things that a Graphics-Configuration can do.

12.3.1. Configuration Information

Most of GraphicsConfiguration's methods return information about the configuration itself:

public abstract GraphicsDevice getDevice()

This method returns the GraphicsDevice associated with this particular configuration.

public abstract ColorModel getColorModel()

This method returns the color model used by the device in this configuration. Physical devices are entirely opaque, so the color model returned by this method doesn't support transparency (alpha values).

public abstract ColorModel getColorModel(int transparency)

This method is the same as above, but returns a color model that supports the requested transparency mode. (If you're wondering what a color model is, take a look back at Chapter 11.) The transparency parameter should be one of the constants from the java.awt.Transparency interface—either OPAQUE, BITMASK, or TRANSLUCENT.

Here's a simple program that displays the color model of the default screen device in its available configurations:

import java.awt.*; public class ShowConfigurations { public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice defaultScreen = ge.getDefaultScreenDevice(); GraphicsConfiguration[] configurations = defaultScreen. getConfigurations(); ...

Get Java 2D Graphics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.