// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;

public class LayoutFun extends JFrame {
    public LayoutFun() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("LayoutFun");
        setPreferredSize(new Dimension(800, 600));
        getContentPane().setLayout(new GridLayout(2, 2));
        JPanel g11 = new JPanel();
        g11.setBorder(new EmptyBorder(5, 5, 5, 5));
        g11.setLayout(new BorderLayout());
        g11.add(new JLabel("BorderLayout"), BorderLayout.NORTH);
        JPanel g11body = new JPanel();
        g11body.setLayout(new BorderLayout());
        g11body.add(new JButton("North"), BorderLayout.NORTH);
        g11body.add(new JButton("South"), BorderLayout.SOUTH);
        g11body.add(new JButton("East"), BorderLayout.EAST);
        g11body.add(new JButton("West"), BorderLayout.WEST);
        g11body.add(new JButton("Center"), BorderLayout.CENTER);
        g11.add(g11body, BorderLayout.CENTER);
        getContentPane().add(g11);
        JPanel g12 = new JPanel();
        g12.setBorder(new EmptyBorder(5, 5, 5, 5));
        g12.setLayout(new BorderLayout());
        g12.add(new JLabel("GridLayout"), BorderLayout.NORTH);
        JPanel g12body = new JPanel();
        g12body.setLayout(new GridLayout(3, 3));
        for(int i = 1; i <= 9; i++) {
            g12body.add(new JButton("" + i));
        }
        g12.add(g12body, BorderLayout.CENTER);
        getContentPane().add(g12);
        JPanel g21 = new JPanel();
        g21.setBorder(new EmptyBorder(5, 5, 5, 5));
        g21.setLayout(new BorderLayout());
        g21.add(new JLabel("FlowLayout"), BorderLayout.NORTH);
        JPanel g21body = new JPanel();
        g21body.setLayout(new FlowLayout());
        for(int i = 1; i <= 9; i++) {
            g21body.add(new JButton("" + i));
        }
        g21.add(g21body, BorderLayout.CENTER);
        getContentPane().add(g21);
        JPanel g22 = new JPanel();
        g22.setBorder(new EmptyBorder(5, 5, 5, 5));
        g22.setLayout(new BorderLayout());
        g22.add(new JLabel("null layout"), BorderLayout.NORTH);
        JPanel g22body = new JPanel();
        g22body.setLayout(null);
        JButton btn2525 = new JButton("(25,25)");
        btn2525.setLocation(25, 25);
        btn2525.setSize(100, 40);
        g22body.add(btn2525);
        JButton btn7575 = new JButton("(75,75)");
        btn7575.setLocation(75, 75);
        btn7575.setSize(100, 40);
        g22body.add(btn7575);
        JButton btn125125 = new JButton("(125,125)");
        btn125125.setLocation(125, 125);
        btn125125.setSize(100, 40);
        g22body.add(btn125125);
        g22.add(g22body, BorderLayout.CENTER);
        getContentPane().add(g22);
        pack();
        
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new LayoutFun();
                f.setVisible(true);
            }
        });
    }
}
