Chapter 6, Transparent and Animated Windows
#46 Slide Notes Out from the Taskbar
H A C K
Slide Notes Out from the Taskbar Hack #46
Pop up a note above the taskbar when your application wants attention.
On Windows, long-running applications sometimes will slide in a window
above the taskbar to call attention to themselves when an interesting event
occurs, such as a finished download or an IM buddy’s appearance.
If you want to do this in Java, you need to deal with a pretty significant
problem: neither AWT nor Swing has any concept of the taskbar (where it
is, how big it is, whether it’s auto-hiding, or anything else). As a result, you
don’t know where to draw the window, and just taking a guess or hardcod-
ing something is hazardous—too high and the window floats inexplicably
on the desktop, too low and it gets buried under the taskbar.
Furthermore, how is this going to work on other operating systems? On the
Mac, the proper way to get attention is to bounce your application’s dock
icon. Since there’s no API exposing that functionality, can you at least use a
Windows-like slide-in window above the dock? Sure…if you can figure out
how tall the dock is (it’s user configurable), or whether the dock is even on
the bottom of the screen (it might be on the right or left, too).
Fortunately, it is possible to figure out what unobstructed space is available
to you on the main display. After that, it’s just a matter of offscreen imaging
Figure Out Where You Are
The key to figuring out your available space is to get the local
GraphicsEnvironment, which describes the display, and then call
getMaximumWindowBounds( ). This method, introduced in Java 1.4, returns a
Rectangle representing the largest centered Window that could fit on the dis-
play, accounting for objects that intrude on the display’s usable space, like
the Windows taskbar or the Mac’s monolithic menu bar.
Figure 6-9. Successive screenshots of an animated glass pane sheet