Indefinite Progress Indicator #47
Chapter 6, Transparent and Animated Windows
Figure 6-11 shows the slide-in window on Mac OS X. It’s less appropriate
on the Mac, and it will be obscured if the user has dock magnification
turned on, but it’s not really bad either.
Hacking the Hack
To expand this hack, the first thing you’d probably want to do is add some
MouseListener so that if the user clicks to acknowledge the appear-
ance of the slide-in window, you could react to it by removing the slide-in
window, bringing your application’s main window to the front, etc. Then
again, you can put live components in here, so there’s no reason you
couldn’t just generate a
JOptionPane, make a JDialog from it, grab the con-
tent pane of that
JDialog, and show it in the slide-in window. That would
give you real, active Swing buttons and handy
JOptionPane return values.
After all, that’s what the sheet example did.
H A C K
Indeﬁnite Progress Indicator Hack #47
Despite its numerous advanced widgets, Swing offers no efficient way to
show that a task of unknown length is in progress. This hack presents two
solutions to address this issue.
Have you ever watched an application do something, but not tell you what
that something is? Other applications let you know what’s going on but
don’t really tell you how long they will need to complete the task. For
instance, the Microsoft Windows copy dialog is famous for its silly (and
lengthy) nonprogress indicators. As a user, I find this very annoying; as a pro-
grammer, I know how difficult it can be to determine the duration of a task.
The Swing Solution
To address this issue, developers created particular widgets meant to show a
task of unknown length is in progress. You can see such a widget in
Mozilla’s installer. It displays an indefinite progress bar—also called a
Cylon—in which a small rectangle bounces back and forth between the two
horizontal edges. I have also seen indefinite progress bars filling like regular
progress bars, going backward once filled and starting all over again. The
Figure 6-11. Slide-in window on Mac OS X with dock on bottom of screen (left) and not
on bottom (right)