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

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);

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