Top Description Inners Fields Constructors Methods
com.sun.jna.platform

public Class WindowUtils

extends Object
Class Inheritance
Imports
java.awt.AWTEvent, .AlphaComposite, .BorderLayout, .Color, .Component, .Container, .Dialog, .Dimension, .Frame, .Graphics, .Graphics2D, .GraphicsConfiguration, .GraphicsDevice, .GraphicsEnvironment, .Point, .Rectangle, .Shape, .Toolkit, .Window, java.awt.event.AWTEventListener, .ComponentEvent, .ComponentListener, .ContainerEvent, .HierarchyEvent, .HierarchyListener, .MouseEvent, .WindowAdapter, .WindowEvent, java.awt.geom.Area, .PathIterator, java.awt.image.BufferedImage, .Raster, java.lang.reflect.Method, java.util.ArrayList, .Arrays, .LinkedList, .List, javax.swing.Icon, .JComponent, .JLayeredPane, .JPanel, .JRootPane, .PopupFactory, .RootPaneContainer, .SwingUtilities, com.sun.jna.Memory, .Native, .NativeLong, .Platform, .Pointer, com.sun.jna.platform.unix.X11, .X11.Display, .X11.GC, .X11.Pixmap, .X11.XVisualInfo, .X11.Xext, .X11.Xrender.XRenderPictFormat, com.sun.jna.platform.win32.GDI32, .Kernel32, .Kernel32Util, .Psapi, .PsapiUtil, .User32, .Win32Exception, .WinBase, .WinDef.DWORDByReference, .WinDef.HBITMAP, .WinDef.HDC, .WinDef.HICON, .WinDef.HRGN, .WinDef.HWND, .WinDef.LPARAM, .WinDef.LRESULT, .WinDef.POINT, .WinDef.RECT, .WinDef.WPARAM, .WinError, .WinGDI, .WinGDI.BITMAP, .WinGDI.BITMAPINFO, .WinGDI.BITMAPINFOHEADER, .WinGDI.ICONINFO, .WinNT, .WinNT.HANDLE, .WinUser, .WinUser.BLENDFUNCTION, .WinUser.SIZE, .WinUser.WNDENUMPROC, com.sun.jna.ptr.ByteByReference, .IntByReference, .PointerByReference, java.util.logging.Level, .Logger

Provides additional features on a Java Window. NOTE: since there is no explicit way to force PopupFactory to use a heavyweight popup, and anything but a heavyweight popup will be clipped by a window mask, an additional subwindow is added to all masked windows to implicitly force PopupFactory to use a heavyweight window and avoid clipping.

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.

Author
Andreas "PAX" Lück, onkelpax-git[at]yahoo.de
See Also
Apple Technote 2007

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
WindowUtils.HeavyweightForcer

This class forces a heavyweight popup on the parent Window.

private static class
WindowUtils.Holder

Canonical lazy loading of a singleton.

private static class
public abstract 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.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final Logger
public static final Shape
MASK_NONE

Use this to clear a window mask.

private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static List<DesktopWindow>

Returns:

A list with all windows and some detailed information.
getAllWindows
(final boolean
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)).
onlyVisibleWindows
)

Requests a list of all currently available Desktop windows.

public static GraphicsConfiguration
getAlphaCompatibleGraphicsConfiguration()

Returns a GraphicsConfiguration comptible with alpha compositing.

public static Dimension

Returns:

Either the requested icon's dimension or an Dimension instance of (0, 0).
getIconSize
(final WinDef.HICON
The icon handle type.
hIcon
)

Detects the size of an icon.

private static WindowUtils.NativeWindowUtils
public static String

Returns:

The full file path of the PE file that is associated with the specified window handle.
getProcessFilePath
(final WinDef.HWND
The concerning window handle for which the PE file path is required.
hwnd
)

Detects the full file path of the process associated with the specified window handle.

public static BufferedImage

Returns:

Either the window's icon or null if an error occurred.
getWindowIcon
(final WinDef.HWND
The concerning window handle.
hwnd
)

Obtains the set icon for the window associated with the specified window handle.

public static Rectangle

Returns:

The location and size of the window.
getWindowLocationAndSize
(final WinDef.HWND
The concerning window handle.
hwnd
)

Requests the location and size of the window associated with the specified window handle.

public static String

Returns:

Either the title or an empty string of no title was found or an error occurred.
getWindowTitle
(final WinDef.HWND
The concerning window handle.
hwnd
)

Tries to obtain the Window's title which belongs to the specified window handle.

public static boolean
isWindowAlphaSupported()

Indicate a window can have a global alpha setting.

public static void
setComponentMask(Component c, Shape mask)

Applies the given mask to the given heavyweight component.

public static void
setWindowAlpha(Window w, float alpha)

Set the overall window transparency.

public static void
setWindowMask(Window w, Shape mask)

Applies the given mask to the given window.

public static void
setWindowMask(Window w, Icon mask)

Applies the given mask to the given window.

public static void
setWindowTransparent(Window w, boolean transparent)

Set the window to be transparent.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait