JDK-4156284 : BoxLayout w/JButton - ignores minimum and preferred sizes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_95
  • CPU: x86
  • Submitted: 1998-07-10
  • Updated: 2001-11-09
  • Resolved: 2001-11-09
Related Reports
Relates :  
Description
Name: rm29839			Date: 07/10/98


Use the supplied Swing 1.02 applet to create a JFrame with a
simple JPanel of buttons.  The 'Load' button is resized correctly to
the width of the 'Preprocessing parameters' button.
Now drag/resize the JFrame and the 'Load' button reverts to
its minimum size despite the fact that the minimum size 
has been reset to equal that of the 'Preprocessing parameters'!!

Applet generated and run under the Symantec 2.5 PDE devel 
environment.

/*
A basic extension of the com.sun.java.swing.JApplet class
*/

import com.sun.java.swing.*;
import java.awt.*;

public class JApplet1 extends JApplet
{
    private JFrame               controlFrame      = null;
    private JButton              loadButn          = null;
    private JButton              preprocButn       = null;
    private JButton              dataStoreButn     = null;
    private JButton              runButn           = null;
    private JButton              stopButn          = null;
    private JButton              inFileOKButn      = null;
	
	public void init()
	{
        JPanel  control_board   = new JPanel();

        controlFrame = new JFrame("WIB");

        // set up a panel containing the main controls
        composeControlBoard(control_board);

		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		getContentPane().setLayout(null);
		setSize(426,266);
		//}}
		
        /*  Tidy up.
         */
        controlFrame.getContentPane().add("Center", control_board);
        controlFrame.pack();
        controlFrame.show();

        // force buttons to correct appearance
    loadButn.setPreferredSize(preprocButn.getSize() );
    loadButn.setMinimumSize(preprocButn.getSize() );
    loadButn.setSize(preprocButn.getSize() );
        dataStoreButn.setSize(preprocButn.getSize() );
        runButn.setSize(stopButn.getSize() );
        repaint();
	}



    /*  Lay out the control panel.
     */
    private void composeControlBoard (JPanel  control_board)
    {
        JPanel  RS_panel   = new JPanel();


        /*  Layout the panel.
         */
        // set up the components
        loadButn = new JButton("Load...");
        loadButn.setBackground(Color.lightGray);
        loadButn.setAlignmentX(Component.LEFT_ALIGNMENT);

        preprocButn = new JButton("Pre-processing Parameters...");
        preprocButn.setBackground(Color.lightGray);
        preprocButn.setAlignmentX(Component.LEFT_ALIGNMENT);

        dataStoreButn = new JButton("Oil Slick Datastore");
        dataStoreButn.setBackground(Color.lightGray);
        dataStoreButn.setAlignmentX(Component.LEFT_ALIGNMENT);

        runButn = new JButton("Run");
        runButn.setBackground(Color.lightGray);
        runButn.setEnabled(false);

        stopButn = new JButton("Stop");
        stopButn.setBackground(Color.lightGray);
        stopButn.setEnabled(false);

        // nest the run and stop buttons in their own panel
        RS_panel.setLayout(new BoxLayout(RS_panel, BoxLayout.X_AXIS) );
        RS_panel.add(runButn);
        RS_panel.add(Box.createGlue() );
        RS_panel.add(stopButn);
        RS_panel.setAlignmentX(Component.LEFT_ALIGNMENT);


	    // lay out the control board components
        control_board.setLayout(new BoxLayout(control_board,
                                              BoxLayout.Y_AXIS) );
        control_board.add(loadButn);
        control_board.add(preprocButn);
        control_board.add(dataStoreButn);
        control_board.add(RS_panel);
        control_board.add(Box.createGlue() );


        /* Tidy up.
         */
        control_board.setMaximumSize(control_board.getPreferredSize() );
    }

}
(Review ID: 34880)
======================================================================

Comments
EVALUATION If one additionally sets the Maximum size, then this does what the developer wants, although I don't know why. Reasigning to Tim, maybe he can explain. jeff.dinkins@Eng 1998-08-03 Name: keR10081 Date: 11/02/2001 BoxLayout takes only maximum size into account. To achieve desired behaviour, use loadButn.setMaximumSize(preprocButn.getSize() ); For more information on BoxLayout, see http://java.sun.com/j2se/1.4/docs/api/javax/swing/BoxLayout.html and http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html This is probably not a bug. ###@###.### ======================================================================
11-06-2004