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


A Top-Level Internal Frame?

As was pointed out in the previous section, mixing internal frames by using the Java look-and-feel on the MS Windows platform looks odd. The native frame contains the Windows titlebar controls and resize border while the internal frames contain the Java look-and-feel titlebar controls and resize border. A pseudo top-level frame can be created by adding an internal frame to a JWindow instance. An example demonstrating this technique is shown in Listing 17.2. The WindowFrameTest application creates the window shown in Figure 17.2.

Listing 17.2 The WindowFrameTest Application

package com.foley.test;

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

import javax.swing.*;

import com.foley.utility.*;

/**
 * An application that displays an internal frame
 * in a JWindow instance. This gives a top-level
 * frame that looks like an internal frame. However,
 * it does not interact with a Window Manager
 * properly.
 *
 * @author Mike Foley
 **/
public class WindowFrameTest extends Object {

    /**
     * Create an internal frame.
     * <p>
     * @return The newly created internal frame.
     **/
    public static JInternalFrame createInternalFrame() {

        final JInternalFrame internalFrame =
                             new JInternalFrame( "Internal JLabel" );
        JMenuBar menuBar = new JMenuBar();

        JMenu file = new JMenu( "File" );
        file.setMnemonic( KeyEvent.VK_F );

        Action exitAction = new ExitAction();
        file.add( exitAction );

        menuBar.add( file );
        internalFrame.setJMenuBar( menuBar );

        JToolBar toolBar = new JToolBar();
        toolBar.add( exitAction );

        internalFrame.getContentPane().add( toolBar,
                                            BorderLayout.NORTH );

        JComponent content = new JLabel( "Internal Frame Content",
                                         SwingConstants.CENTER );
        content.setBorder( BorderFactory.createLoweredBevelBorder() );
        internalFrame.getContentPane().add(
                            content,
                            BorderLayout.CENTER );
        internalFrame.setResizable( true );
        internalFrame.setClosable( true );
        internalFrame.setIconifiable( true );
        internalFrame.setMaximizable( true );
        internalFrame.pack();

               return( internalFrame );
    }

    /**
     * Application entry point.
     * Create the window, add an internal frame
     * and display.
     *
     * @param args Command line parameter. Not used.
     **/
    public static void main( String args[] ) {

        JWindow window = new JWindow();
        JInternalFrame internalFrame = createInternalFrame();

        window.getContentPane().add( internalFrame,
                                     BorderLayout.CENTER );
        window.setLocation( new Point( 200, 100 ) );
        window.setSize( new Dimension( 400, 300 ) );
        window.setVisible( true );

    } // main

} // WindowFrameTest


Figure 17.2  The WindowFrameTest application.

As can be seen in Figure 17.2, the window appears to be a top-level frame that possesses the Java look-and-feel. Unfortunately, the controls on the internal frame do not interact with the system’s window manager. This means that pressing the iconify button on the titlebar does not iconify the window. The JFC developers realize the need for a frame that is entirely drawn by JFC classes. This will allow top-level frames, similar to the window created by the WindowFrameTest application, that will interact with the system’s window manager. Once this type of frame is part of the JFC, internal frames and top-level frames can be drawn with any desired look.

The JDesktopPane Class

The previous section described many of the options available in the JInternalFrame class. An example was presented where an internal frame was added to the content pane of a JFrame instance. While this is a valid use of an internal frame, the class was designed to be used in conjunction with the JDesktopPane class. When an internal frame is added to a desktop pane, the internal frame behaves as an independent frame in the desktop pane.

The JDesktopPane class extends the JLayeredPane class. It creates a virtual desktop to be used by internal frames. It manages the potential overlap when multiple children are added to a desktop pane. The JDesktopPane class provides the link between the internal frames and the DesktopManager instance installed by the current look-and-feel. The desktop manager is responsible for performing the operations on the internal frame. For example, when an internal frame is to be iconified, it is the DesktopManager that performs the operation. This allows a look-and-feel to specify how these operations are performed.

There are not very many methods in the JDesktopPane class that are typically called by application code. The two that are of interest are the getAllFrames method and the getAllFramesInLayer method. The getAllFrames method returns an array of all JInternalFrame instances contained in the desktop pane, and the getAllFramesInLayer returns an array of the internal frames in a particular layer in the desktop pane. The getDesktopManager method will return a reference to the DesktopManager associated with the desktop pane.


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.