public final class AWTUtilities extends Object
Window class (or its
descendant, such as JFrame).
Some of the mentioned features may not be supported by the native platform.
To determine whether a particular feature is supported, the user must use
the isTranslucencySupported() method of the class passing a desired
translucency kind (a member of the Translucency enum) as an
argument.
The per-pixel alpha feature also requires the user to create her/his
windows using a translucency-capable graphics configuration.
The isTranslucencyCapable() method must
be used to verify whether any given GraphicsConfiguration supports
the trasnlcency effects.
WARNING: This class is an implementation detail and only meant for limited use outside of the core platform. This API may change drastically between update release, and it may even be removed or be moved in some other package(s)/class(es).
| Modifier and Type | Class and Description |
|---|---|
static class |
AWTUtilities.Translucency
Kinds of translucency supported by the underlying system.
|
| Modifier and Type | Method and Description |
|---|---|
static float |
getWindowOpacity(Window window)
Get the opacity of the window.
|
static Shape |
getWindowShape(Window window)
Returns an object that implements the Shape interface and represents
the shape previously set with the call to the setWindowShape() method.
|
static boolean |
isTranslucencyCapable(GraphicsConfiguration gc)
Verifies whether a given GraphicsConfiguration supports
the PERPIXEL_TRANSLUCENT kind of translucency.
|
static boolean |
isTranslucencySupported(AWTUtilities.Translucency translucencyKind)
Returns whether the given level of translucency is supported by
the underlying system.
|
static boolean |
isWindowOpaque(Window window)
Returns whether the window is opaque or translucent.
|
static void |
setComponentMixingCutoutShape(Component component,
Shape shape)
Sets a 'mixing-cutout' shape for the given component.
|
static void |
setWindowOpacity(Window window,
float opacity)
Set the opacity of the window.
|
static void |
setWindowOpaque(Window window,
boolean isOpaque)
Enables the per-pixel alpha support for the given window.
|
static void |
setWindowShape(Window window,
Shape shape)
Sets a shape for the given window.
|
public static boolean isTranslucencySupported(AWTUtilities.Translucency translucencyKind)
translucencyKind - a kind of translucency support
(either PERPIXEL_TRANSPARENT,
TRANSLUCENT, or PERPIXEL_TRANSLUCENT)public static void setWindowOpacity(Window window, float opacity)
Also note that the window must not be in the full-screen mode when setting the opacity value < 1.0f. Otherwise the IllegalArgumentException is thrown.
window - the window to set the opacity level toopacity - the opacity level to set to the windowNullPointerException - if the window argument is nullIllegalArgumentException - if the opacity is out of
the range [0..1]IllegalArgumentException - if the window is in full screen mode,
and the opacity is less than 1.0fUnsupportedOperationException - if the TRANSLUCENT translucency
kind is not supportedpublic static float getWindowOpacity(Window window)
window - the window to get the opacity level fromNullPointerException - if the window argument is nullpublic static Shape getWindowShape(Window window)
window - the window to get the shape fromNullPointerException - if the window argument is nullpublic static void setWindowShape(Window window, Shape shape)
Note that in order to set a shape, the window must be undecorated.
If the window is decorated, this method ignores the shape
argument and resets the shape to null.
Also note that the window must not be in the full-screen mode when setting a non-null shape. Otherwise the IllegalArgumentException is thrown.
Depending on the platform, the method may return without
effecting the shape of the window if the window has a non-null warning
string (Window.getWarningString()). In this case the passed
shape object is ignored.
window - the window to set the shape toshape - the shape to set to the windowNullPointerException - if the window argument is nullIllegalArgumentException - if the window is in full screen mode,
and the shape is not nullUnsupportedOperationException - if the PERPIXEL_TRANSPARENT
translucency kind is not supportedpublic static void setWindowOpaque(Window window, boolean isOpaque)
Note that in order for the window to support the per-pixel alpha
mode, the window must be created using the GraphicsConfiguration
for which the isTranslucencyCapable(java.awt.GraphicsConfiguration)
method returns true.
Also note that some native systems enable the per-pixel translucency mode for any window created using the translucency-compatible graphics configuration. However, it is highly recommended to always invoke the setWindowOpaque() method for these windows, at least for the sake of cross-platform compatibility reasons.
Also note that the window must not be in the full-screen mode when making it non-opaque. Otherwise the IllegalArgumentException is thrown.
If the window is a Frame or a Dialog, the window must
be undecorated prior to enabling the per-pixel translucency effect (see
Frame#setUndecorated() and/or Dialog#setUndecorated()).
If the window becomes decorated through a subsequent call to the
corresponding setUndecorated() method, the per-pixel
translucency effect will be disabled and the opaque property reset to
true.
Depending on the platform, the method may return without
effecting the opaque property of the window if the window has a non-null
warning string (Window.getWarningString()). In this case
the passed 'isOpaque' value is ignored.
window - the window to set the shape toisOpaque - whether the window must be opaque (true),
or translucent (false)NullPointerException - if the window argument is nullIllegalArgumentException - if the window uses
a GraphicsConfiguration for which the
isTranslucencyCapable()
method returns falseIllegalArgumentException - if the window is in full screen mode,
and the isOpaque is falseIllegalArgumentException - if the window is decorated and the
isOpaque argument is false.UnsupportedOperationException - if the PERPIXEL_TRANSLUCENT
translucency kind is not supportedpublic static boolean isWindowOpaque(Window window)
window - the window to set the shape toNullPointerException - if the window argument is nullpublic static boolean isTranslucencyCapable(GraphicsConfiguration gc)
setWindowOpaque(java.awt.Window, boolean)
method must be created using a GraphicsConfiguration for which this method
returns true.
Note that some native systems enable the per-pixel translucency mode for any window created using a translucency-capable graphics configuration. However, it is highly recommended to always invoke the setWindowOpaque() method for these windows, at least for the sake of cross-platform compatibility reasons.
gc - GraphicsConfigurationNullPointerException - if the gc argument is nullpublic static void setComponentMixingCutoutShape(Component component, Shape shape)
The shape argument may have the following values:
null - reverts the default cutout shape (the rectangle equal
to the component's getBounds())
new Rectangle().
The most common example when the 'mixing-cutout' shape is needed is a
glass pane component. The JRootPane#setGlassPane() method
automatically sets the empty-shape as the 'mixing-cutout' shape
for the given glass pane component. If a developer needs some other
'mixing-cutout' shape for the glass pane (which is rare), this must be
changed manually after installing the glass pane to the root pane.
Note that the 'mixing-cutout' shape neither affects painting, nor the mouse events handling for the given component. It is used exclusively for the purposes of the Heavyweight/Lightweight Components Mixing feature.
component - the component that needs non-default
'mixing-cutout' shapeshape - the new 'mixing-cutout' shapeNullPointerException - if the component argument is null