Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Search this book:
 
Search the site:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


Internal Frame Versions

Each of the methods presented thus far for displaying a dialog box by using the JOptionPane class creates a dialog box in its own frame. This allows the dialog box to be moved independently from its parent frame. There are also versions of each of these methods that create an internal frame version of the dialog box. A complete guide to internal frames is given in Chapter 17, “Internal Frames.”

Table 18.5 shows the list of methods that create frames and the corresponding internal frame version of the methods.

Table 18.5 Internal Frame Method Names

Frame Version Internal Frame Version

CreateDialog CreateInternalFrame
ShowConfirmDialog ShowInternalConfirmDialog
ShowInputDialog ShowInternalInputDialog
ShowMessageDialog ShowInternalMessageDialog
showOptionDialog ShowInternalOptionDialog

Just as the showXXXDialog methods contain many overloaded variants of each method, there are many overloaded variants of the showInternalXXXDialog methods. The functionality of these methods is the same for the external and internal frame versions. The primary difference is in the presentation of the dialog box. The internal versions of the dialog box cannot extend beyond the frame of their parent component. At the present time, the internally framed dialog boxes cannot be resized. However, there is no apparent reason for this restriction, and it may be lifted in a future version of the internal frame dialog boxes. The internal frame dialog boxes are the entire width of their parent component. This appears to be a bug in these dialog boxes. Unlike the non-internal dialog boxes in the JOptionPane class, the showInternalXXXDialog methods must be passed a non-null parent. This parameter defines the frame where the dialog box will be displayed.

The JInternalOptionTest application shown in Listing 18.3 creates buttons in its content pane. Each button opens a different variant of the internal message dialog box by using the JOptionPane class. The application after being resized larger than its packed size is shown in Figure 18.14. Figure 18.15 shows the application after the Warning Dialog Box button was pressed. The internal dialog box is shown below the buttons in the application. Notice how displaying the internal dialog box also repositioned the buttons. The same undesirable behavior is exhibited when using the Windows look-and-feel. This is shown in Figure 18.16.


Figure 18.14  JInternalOption-Test application before displaying internal dialog box.


Figure 18.15  JInternalOption-Test after displaying internal warning dialog box.


Figure 18.16  JInternalOption-Test after displaying internal error dialog box using the Windows look-and-feel.

The initial implementation of the internal frame dialog boxes contained in the JOptionPane class is of inferior quality to the external frame versions of equivalent dialog boxes. The current implementation throws many exceptions in the user interface classes. The current state of these dialog boxes is unusable in a commercial quality application.

Listing 18.3 JInternalOptionTest Application

package com.foley.test;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import com.foley.utility.ApplicationFrame;
import com.foley.utility.JBox;

/**
 * An application that displays an internal
 * JOptionPane dialog box.
 *
 * @author Mike Foley
 **/
public class JInternalOptionTest extends Object {

    private JFrame frame;

    /**
     * JInternalOptionTest, default Constructor.
     * <p>
     * Create a frame. Add some buttons that display
     * an internal JOptionPane when activated.
     **/
    public JInternalOptionTest() {
        frame = new ApplicationFrame( “Internal Dialog Test” );

        JComponent content = createContent();
        content.setBorder( BorderFactory.createLoweredBevelBorder() );
        frame.getContentPane().add( content );

        frame.pack();
        frame.setVisible( true );
    }

    protected JComponent createContent() {
        JBox box = JBox.createVerticalJBox();

        JButton errorMessageButton = new JButton( “Error Dialog Box” );
        errorMessageButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent event ) {

               JOptionPane.showInternalMessageDialog( ( Component
 )event.getSource(),
                                “Message”,
                                “Error Message Dialog”,
                                JOptionPane.ERROR_MESSAGE );
            } // actionPerformed
        } );
        box.add( errorMessageButton );

        JButton informationMessageButton = new JButton(
  “Information Dialog Box” );
        informationMessageButton.
addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
Object[] message = { “TEST”, “If you have a lot of information”,
                                     “to display to the user, you may”,
                                    “give an array of objects to the”,
                                     “message box.”,
                                     “ “,
“The dialog box will display each object”,
                                     “on its own line, and size”
                                     “the dialog”, properly to fit”
                                     “each object” };
                JOptionPane.showInternalMessageDialog( ( Component
 )event.getSource(),
                                message,
                                “Information Message Dialog”,
                                JOptionPane.INFORMATION_MESSAGE );
            } // actionPerformed
        } );
        box.add( informationMessageButton );

JButton warningMessageButton = new JButton( “Warning Dialog Box” );
        warningMessageButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                JOptionPane.showInternalMessageDialog( ( Component
 )event.getSource(),
                                “Something is bad”,
                                “Warning Message Dialog”,
                                JOptionPane.WARNING_MESSAGE );
            } // actionPerformed
        } );
        box.add( warningMessageButton );

JButton questionMessageButton = new JButton( “Question Dialog Box” );
        questionMessageButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent event ) {
                Object[] nodes = { “Node1”, “Node2”, “Node3” };
                JOptionPane.showInternalMessageDialog( ( Component
 )event.getSource(),
                                new JTree( nodes ),
                                “Question Message Dialog”,
                                JOptionPane.QUESTION_MESSAGE );
            }
        } );
        box.add( questionMessageButton );

        return( box );
    }
    /**
     * Application entry point.
     * Create an instance of the test application.
     *
     * @param args Command line parameter. Not used.
     **/
    public static void main( String args[] ) {

        //
        // Enable this code for the windows L&F.
        // Only valid on the MS Windows platform.
        //
        /*
        try {
            UIManager.setLookAndFeel(
“com.sun.java.swing.plaf.windows.WindowsLookAndFeel” );
        } catch( Exception ex ) {
System.err.println( “Exception: “ + ex.getLocalizedMessage() );
        }
        */
        new JInternalOptionTest();
    } // main

} // JInternalOptionTest


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.