[translucent window PIC] Chapter 10.   Ghostly, Shapely Windows

 

It's time to give your favorite application a makeover, perking up its tired, overly familiar GUI.

A ghostly window is one that that can be translucent, and shapely means that the window may be non-rectangular. Translucency utilizes the Win32 API's layered window support for alpha-blending (see Hack 10.1), while Win32 regions (rectangles, rounded rectangles, polygons, ellipses, and combinations) can be employed to mask portions of a window to change its shape (Hack 10.2). [oval window PIC]

Regions are easiest to work with when the window's size is fixed, but Hack 10.3 shows an efficient way of handling resizing.

A shapely window implemented with regions can look a bit ugly since parts of the title bar, borders, and components are cut away. Hack 10.4 suggests a few tricks for fixing these problems, based around an undecorated JFrame and a specialized JPanel.

The undecorated JFrame and specialized panel makes an appearance in Hack 10.5 as well, where we implement shapely windows using a transparent pixel color. This approach allows a window to be almost any shape you wish. [blob window PIC]

It's useful to divide translucency into two types: global translucency, applied to an entire window and all its components (as seen in Hack 10.1), and a more versatile form called per-pixel translucency. It allows different parts of a window to exhibit different degrees of translucency, and is often used to soften the edges of curved windows to give them a smoother look. Hack 10.6 demonstrates how to employ a per-pixel translucent image to shape a JFrame.

Hack 10.7. utilizes global translucency and regions to animate a window's closing behavior. We describe two examples: a window that closes by fading away, and a window that is gradually cut down to nothing. [fading window PIC]

A great way of improving a window's appearance is to change its pluggable look and feel (L&F). Hack 10.8 shows how to use Java's standard L&Fs, and we also experiment with some third-party L&Fs (Substance and Napkin). [silver L&F window PIC] [nemo L&F window PIC]

 

Downloads


Navigation:


Dr. Andrew Davison
E-mail: ad@coe.psu.ac.th
Back to my home page