public class WindowUtils extends Object
Window
.
NOTE: Neither shaped windows nor transparency currently works with Java 1.4 under X11. This is at least partly due to 1.4 using multiple X11 windows for a single given Java window. It *might* be possible to remedy by applying the window region/transparency to all descendants, but I haven't tried it. In addition, windows must be both displayable and visible before the corresponding native Drawable may be obtained; in later Java versions, the window need only be displayable.
NOTE: If you use setWindowMask(Window,Shape)
and override Window.paint(Graphics)
on OS X, you'll need to explicitly set the clip
mask on the Graphics
object with the window mask; only the
content pane of the window and below have the window mask automatically
applied.
NOTE: On OSX, the property
apple.awt.draggableWindowBackground
is set automatically when
a window's background color has an alpha component. That property must be
set to its final value before the heavyweight peer for the Window
is created. Once Component.addNotify()
has been called on the
component, causing creation of the heavyweight peer, changing this
property has no effect.
Modifier and Type | Class and Description |
---|---|
static class |
WindowUtils.NativeWindowUtils
Window utilities with differing native implementations.
|
protected static class |
WindowUtils.RepaintTrigger
This can be installed over a
JLayeredPane in order to
listen for repaint requests. |
Modifier and Type | Field and Description |
---|---|
static Shape |
MASK_NONE
Use this to clear a window mask.
|
Constructor and Description |
---|
WindowUtils() |
Modifier and Type | Method and Description |
---|---|
static List<DesktopWindow> |
getAllWindows(boolean onlyVisibleWindows)
Requests a list of all currently available Desktop windows.
|
static GraphicsConfiguration |
getAlphaCompatibleGraphicsConfiguration()
Returns a
GraphicsConfiguration comptible with alpha
compositing. |
static Dimension |
getIconSize(WinDef.HICON hIcon)
Detects the size of an icon.
|
static String |
getProcessFilePath(WinDef.HWND hwnd)
Detects the full file path of the process associated with the specified
window handle.
|
static BufferedImage |
getWindowIcon(WinDef.HWND hwnd)
Obtains the set icon for the window associated with the specified
window handle.
|
static Rectangle |
getWindowLocationAndSize(WinDef.HWND hwnd)
Requests the location and size of the window associated with the
specified window handle.
|
static String |
getWindowTitle(WinDef.HWND hwnd)
Tries to obtain the Window's title which belongs to the specified window
handle.
|
static boolean |
isWindowAlphaSupported()
Indicate a window can have a global alpha setting.
|
static void |
setComponentMask(Component c,
Shape mask)
Applies the given mask to the given heavyweight component.
|
static void |
setWindowAlpha(Window w,
float alpha)
Set the overall window transparency.
|
static void |
setWindowMask(Window w,
Icon mask)
Applies the given mask to the given window.
|
static void |
setWindowMask(Window w,
Shape mask)
Applies the given mask to the given window.
|
static void |
setWindowTransparent(Window w,
boolean transparent)
Set the window to be transparent.
|
public static final Shape MASK_NONE
public static void setWindowMask(Window w, Shape mask)
public static void setComponentMask(Component c, Shape mask)
public static void setWindowMask(Window w, Icon mask)
public static boolean isWindowAlphaSupported()
public static GraphicsConfiguration getAlphaCompatibleGraphicsConfiguration()
GraphicsConfiguration
comptible with alpha
compositing.public static void setWindowAlpha(Window w, float alpha)
NOTE: Windows requires that sun.java2d.noddraw=true
in order for alpha to work.
NOTE: On OSX, the property
apple.awt.draggableWindowBackground
must be set to its
final value before the heavyweight peer for the Window is
created. Once Component.addNotify()
has been called on the
component, causing creation of the heavyweight peer, changing this
property has no effect.
public static void setWindowTransparent(Window w, boolean transparent)
apple.awt.draggableWindowBackground
must be set to its final value before the heavyweight peer for
the Window is created. Once Component.addNotify()
has been
called on the component, causing creation of the heavyweight peer,
changing this property has no effect.public static BufferedImage getWindowIcon(WinDef.HWND hwnd)
hwnd
- The concerning window handle.null
if an error
occurred.public static Dimension getIconSize(WinDef.HICON hIcon)
hIcon
- The icon handle type.Dimension
instance of (0, 0)
.public static List<DesktopWindow> getAllWindows(boolean onlyVisibleWindows)
onlyVisibleWindows
- Specifies whether only currently visible windows will be
considered (true
). That are windows which are not
minimized. The WS_VISIBLE
flag will be checked (see:
User32.IsWindowVisible(HWND)).public static String getWindowTitle(WinDef.HWND hwnd)
hwnd
- The concerning window handle.public static String getProcessFilePath(WinDef.HWND hwnd)
hwnd
- The concerning window handle for which the PE file path is
required.public static Rectangle getWindowLocationAndSize(WinDef.HWND hwnd)
hwnd
- The concerning window handle.