import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
 
public class GridBagLayoutDemo
{ 
    private static void createGUI()                             //Create and set up the window.
    {
        JFrame frame = new JFrame("GridBagLayoutDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         
        Container pane = frame.getContentPane(); 
        addComponents(pane);                                    //call the addComponents() method below
 
        frame.pack();
        frame.setVisible(true);
    }

    private static void addComponents(Container pane) 
    { 
        GridBagLayout      g = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
 
        pane.setLayout(g);
        pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

        JButton button;
        JLabel  label; 

        Border beveledTop = BorderFactory.createRaisedBevelBorder();
        Border beveledBot = BorderFactory.createLoweredBevelBorder();
        Border coumpound  = BorderFactory.createCompoundBorder(beveledTop, beveledBot); 
 
        button = new JButton("Button 1");
        c.gridy   = 0;                                      //first row                             
        c.gridx   = 0;                                      //first column
        c.weightx = 0.5;                                    //half the width % when resizing
        c.fill    = GridBagConstraints.HORIZONTAL;          //fill horizontally
        pane.add(button, c);
 
        button = new JButton("Button 2");
        c.gridy   = 0;
        c.gridx   = 1;
        c.weightx = 1;
        c.fill    = GridBagConstraints.HORIZONTAL;
        pane.add(button, c);
 
        button = new JButton("Button 3");
        c.gridy   = 0;                                      
        c.gridx   = 2;                                      
        c.weightx = 1;                                      
        c.fill    = GridBagConstraints.HORIZONTAL;          
        pane.add(button, c);

        label = new JLabel("Big Area for Screen", SwingConstants.CENTER);
        c.gridy     = 1;                                    //second row
        c.gridx     = 0;                                    //first column
        c.gridwidth = 4;                                    //4 columns wide
        c.ipady     = 200;                                  //vertical padding 60px
        c.ipadx     = 400;                                  //horizontal padding 90px
        c.weightx   = 1;
        c.weighty   = 1;                                    //request any extra vertical space
        c.fill      = GridBagConstraints.BOTH;
        pane.add(label, c);
 
        label = new JLabel("Footer", SwingConstants.CENTER);
        label.setBorder(coumpound);
        c.gridy     = 2;                                   //third row
        c.gridx     = 1;                                   //second column
        c.gridwidth = 2;                                   //2 columns wide
        c.ipady     = 0;                                   //inside vertical padding
        c.ipadx     = 0;                                   //inside horizontal padding
        c.insets    = new Insets(5,0,10,5);                //outside padding top/left/bottom/right
        c.fill      = GridBagConstraints.HORIZONTAL;
        c.anchor    = GridBagConstraints.PAGE_END;         //anchor to bottom of space
        pane.add(label, c);
    }
 
 
    public static void main(String[] args)
    {
        createGUI();
    }
}