O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

202
|
Chapter 5, Windows, Dialogs, and Frames
#39 Spin Open a Detail Pane
HACK
to ever have a reference to the dialog. With DialogEarthquakeCenter, how-
ever, you need that reference. So, instead, you provide the usual
JOptionPane
values (message, message type, user options, etc.) to the
JOptionPane
con-
structor, and then derive a dialog with
createDialog( )
. Don’t worry—you
still end up with the same option dialog.
Next, you create a
DialogEarthquakeCenter
from that dialog. Then you can
return to the dialog,
pack( ) it, and make it visible. One hazard of working
with the
JOptionPane dialog is that it is modal, meaning it will block the
AWT event-dispatch thread when shown; thus, it won’t shake because
DialogEarthquakeCenter won’t get any animation callbacks from Timer. To
get around this, I just made the dialog non-modal—after all, the user proba-
bly isn’t going to be able to click it when it’s moving. Another option might
be for the
DialogEarthquakeCenter constructor to remember if its dialog is
modal, and to reset this state in
stopShake( ).
Unfortunately, there’s not a great way to show the effect of this animation in
book form. The best I can suggest is that you compile and run the hack for
yourself. While you’re at it, change some of the constant values to see the
effect of longer or shorter shake cycles, distances, and durations.
H A C K
#39
Spin Open a Detail Pane Hack #39
You don’t want to bombard the user with details, but you don’t want to hide
them either. Here’s a way to let the user pop open a More Info widget.
You have to be careful not to weigh down your GUIs with so much informa-
tion that the user can’t see what really matters. On the other hand, there are
times that the user may want more information than is obvious on one
screen or panel. A simple way of dealing with this is to put a More Info but-
ton that pops up a new window. That leads to the annoyance of having too
many windows on the screen, none associated in any way with their source.
Mac OS X has a nice idea: the spin open disclosure widget. It works like
this: you have a component of some sort—perhaps a simple label or a com-
plex panel—with a triangle-shaped spinner below it. When the user clicks
the spinner, a whole new widget opens up below the spinner, offering more
information. In fact, the new widget can have significant functionality: to set
file permissions from the Finder, you open a Get Info window and spin open
an Ownership and Permissions section to set your own access (if you own
the file), and a second Details spinner lets you set access levels for the
owner, group, and others.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required