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


Controlling Component Sizes

The JSplitPane class manages two AWT component children. When either or both of these components are instances of the JComponent class, the JSplitPane class respects the minimumSize property of the child. If this property is set to a nonzero value in the child component, the divider can’t move into a position that would make that component smaller than its minimum size. However, if the split pane is contained in the content pane of a JFrame instance, as in the JSplitPaneTest application shown earlier in this chapter, resizing the frame can make a component smaller than its minimum size. This causes the divider to jump to the component’s minimum size the next time the user drags it.

When the split pane is smaller than the combined minimum sizes of its managed children, the user cannot drag the divider. Unfortunately, the user doesn’t get any visual feedback that this condition has been entered. The cursor still changes to the Resize icon, telling the user that the divider can be dragged. This gives the user the impression that there is something wrong with the application when in fact there is not. To correct this problem, the splitpane should not change the shape of the cursor to the Resize icon when the user is not able to resize the panes.

The components managed by the split pane can be reset to their preferred sizes through the resetToPreferredSize method. The divider will be moved to the appropriate location in the split pane after the components are sized.

A commonly misunderstood aspect of the JSplitPane class is the minimumSize property. If the components managed by the split pane have 0 in the Split dimension, the split pane will give its entire area to one of the components, and the other component will not be seen. This condition is demonstrated by the JSplitPaneTest2 application, shown in Listing 16.2. The resulting window is shown in Figure 16.5. To alleviate this condition, the minimumSize property can be set on the component or the location of the divider can be specified by the application.

Listing 16.2 The JSplitPaneTest2 Application

package com.foley.test;

import java.awt.*;

import javax.swing.*;

import com.foley.utility.ApplicationFrame;

/**
 * An application that displays a JSplitPane in a frame.
 * It demonstrates a 0 minimum size of one of the components
 * in the split pane.
 * <p>
 * @author Mike Foley
 **/
public class JSplitPaneTest2 extends Object {

    /**
     * The splitPane for the test.
     **/
    JSplitPane splitPane;

    /**
     * JSplitPaneTest2, Constructor
     * <p>
     * Create a splitpane and add a table and tabbed pane
     * to the splitpane.
     **/
    public JSplitPaneTest2() {
        splitPane = new JSplitPane();

        splitPane.setRightComponent(
                  new JScrollPane( new JLabel( "Hello" ) ) );

        JComponent left = new JComponent() {};
        splitPane.setLeftComponent( left );

    }

    /**
     * @return The split pane.
     **/
    public JSplitPane getSplitPane() {
        return( splitPane );
    }

    /**
     * Application entry point.
     * Create the frame, and display a splitpane in it.
     *
     * @param args Command line parameter. Not used.
     **/
    public static void main( String args[] ) {

        JFrame frame = new ApplicationFrame( "JSplitPaneTest2" );
        JSplitPaneTest2 test = new JSplitPaneTest2();

        frame.getContentPane().add( test.getSplitPane(),
                                    BorderLayout.CENTER );
        frame.pack();
        frame.setVisible( true );
    } // main
} // JSplitPaneTest2


Figure 16.5  A JSplitPane with a 0 minimum size component.


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.