206
|
Chapter 5, Windows, Dialogs, and Frames
#39 Spin Open a Detail Pane
HACK
Now You See Me
To show a non-trivial use of the MoreInfoPanel, the TestMoreInfoPanel class
shown in Example 5-8 creates a
JOptionPane dialog, hijacks its content pane,
and puts that into a
MoreInfoPanel
as the top component. The bottom com-
ponent is a
JTextArea
with a more detailed (or obnoxious, in this case)
description of the warning in the dialog. This
MoreInfoPanel
is then reset as
the dialog’s content pane. The initial result looks like Figure 5-9.
Figure 5-9. A Warning dialog with a closed MoreInfoPanel
Example 5-8. A spin-open dialog using a MoreInfoPanel
import java.awt.*;
import javax.swing.*;
public class TestMoreInfoPanel {
public static void main (String[] args) {
JOptionPane pane =
new JOptionPane ("The action you have chosen to perform\n is " +
"not recommended.",
JOptionPane.WARNING_MESSAGE);
JDialog dialog = pane.createDialog (null, "Warning");
Container grabbedContent = dialog.getContentPane( );
JTextArea area =
new JTextArea ("No, seriously dude, you are about to totally "+
"bake your computer, if not your entire " +
"network, if you don't bail right now. Think " +
"I'm kidding? Would I go to such lengths to " +
"provide such an elaborate warning message if " +
"I were kidding? No, no, wait... you know " +
"what? Go ahead. Click OK and blow everything " +
"to kingdom come. See if I care.",
5, 40);
area.setLineWrap (true);
area.setWrapStyleWord (true);

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.