import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

    // Compare the effects of glue, rigid areas and struts
    // within two Boxes and a JPanel.
class SwingBoxFrame2 extends JFrame {
    public SwingBoxFrame2() {
        final int width = 300, height = 175;
        setSize(width,height);

        Container contents = getContentPane();

        // This box will contain horizontal glue.
        Box glueBox = Box.createHorizontalBox();
        glueBox.add(Box.createHorizontalGlue());
        glueBox.add(new JButton("Glue 1"));
        glueBox.add(Box.createHorizontalGlue());
        glueBox.add(new JButton("Glue 2"));

        // This panel will contain rigid areas. Use a bordered panel in
        // order to show the relative size of each area, and the positioning
        // of the buttons within them.
        JPanel rigidPanel = new JPanel();
        rigidPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
        rigidPanel.setLayout(new BoxLayout(rigidPanel,BoxLayout.X_AXIS));
        rigidPanel.add(new JButton("Rigid 1"));
        // Separate the two buttons.
        final int areaWidth = 50, areaHeight = 40;
        rigidPanel.add(Box.createRigidArea(
                        new Dimension(areaWidth,areaHeight)));
        rigidPanel.add(new JButton("Rigid 2"));

        // This box will contain horizontal struts.
        Box strutBox = Box.createHorizontalBox();
        final int strutWidth = 50;
        // Fix the first button from the left side.
        strutBox.add(Box.createHorizontalStrut(strutWidth));
        strutBox.add(new JButton("Strut 1"));
        // Fix the second button from the first.
        strutBox.add(Box.createHorizontalStrut(strutWidth));
        strutBox.add(new JButton("Strut 2"));

        // Place the three containers vertically within a panel.
        JPanel centerPanel = new JPanel();
        final int rows = 3, cols = 1;
        centerPanel.setLayout(new GridLayout(rows,cols));
        centerPanel.add(glueBox);
        centerPanel.add(rigidPanel);
        centerPanel.add(strutBox);

        contents.add(centerPanel,"Center");
        JPanel quitPanel = new QuitJPanel();
        contents.add(quitPanel,"South");
    }
}
