import javax.swing.*;

/**
 * A demo class showing layout implementation of the Address Book form from
 * John O'Connor's "Layout Manager Showdown" blog:
 * http://weblogs.java.net/blog/joconner/archive/2006/10/more_informatio.html
  */
public class AddressBookDemo_GroupLayout extends JFrame {
    public AddressBookDemo_GroupLayout() {
        JScrollPane scrollpane = new JScrollPane();
        JList namesList = new JList(new String[] {
            "Bugs Bunny", "Sylvester Cat", "Wile  Coyote", "Tasmanian Devil",
            "Daffy Duck", "Elmer Fudd", "Pepe Le Pew", "Marvin Martian"
        });
        JLabel lastNameLabel = new JLabel();
        JTextField lastNameField = new JTextField();
        JLabel firstNameLabel = new JLabel();
        JTextField firstNameField = new JTextField();
        JLabel phoneLabel = new JLabel();
        JTextField phoneField = new JTextField();
        JLabel emailLabel = new JLabel();
        JTextField emailField = new JTextField();
        JLabel address1Label = new JLabel();
        JTextField address1Field = new JTextField();
        JLabel address2Label = new JLabel();
        JTextField adress2Field = new JTextField();
        JLabel cityLabel = new JLabel();
        JTextField cityField = new JTextField();
        JLabel stateLabel = new JLabel();
        JTextField stateField = new JTextField();
        JLabel countryLabel = new JLabel();
        JTextField countryField = new JTextField();
        JLabel postalLabel = new JLabel();
        JTextField postalField = new JTextField();
        JButton newButton = new JButton();
        JButton cancelButton = new JButton();
        JButton deleteButton = new JButton();
        JButton editButton = new JButton();
        JButton saveButton = new JButton();

        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        scrollpane.setViewportView(namesList);

        lastNameLabel.setText("Last Name:");
        lastNameField.setText("Martian");
        firstNameLabel.setText("First Name:");
        firstNameField.setText("Marvin");
        phoneLabel.setText("Phone:");
        phoneField.setText("805-876-5432");
        emailLabel.setText("Email:");
        emailField.setText("marvin@wb.com");
        address1Label.setText("Address 1:");
        address1Field.setText("1001001010101 Martian Way");
        adress2Field.setText("Suite 10111011");
        address2Label.setText("Address 2:");
        cityLabel.setText("City:");
        cityField.setText("Ventura");
        stateLabel.setText("State:");
        stateField.setText("CA");
        countryLabel.setText("Country:");
        postalLabel.setText("Postal Code:");
        postalField.setText("93001");
        newButton.setText("New");
        cancelButton.setText("Cancel");
        deleteButton.setText("Delete");
        editButton.setText("Edit");
        saveButton.setText("Save");

        GroupLayout layout = new GroupLayout(getContentPane());
        layout.setAutoCreateGaps(true);
        layout.setAutoCreateContainerGaps(true);
        getContentPane().setLayout(layout);

layout.setHorizontalGroup(layout.createSequentialGroup()
    .addComponent(scrollpane, GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
    .addGroup(layout.createParallelGroup()
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                .addComponent(lastNameLabel)
                .addComponent(phoneLabel)
                .addComponent(address1Label)
                .addComponent(address2Label)
                .addComponent(cityLabel)
                .addComponent(stateLabel)
                .addComponent(countryLabel))
            .addGroup(layout.createParallelGroup()
                .addComponent(address1Field)
                .addComponent(adress2Field)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup()
                        .addComponent(lastNameField)
                        .addComponent(phoneField)
                        .addComponent(cityField)
                        .addComponent(stateField)
                        .addComponent(countryField))
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(firstNameLabel)
                            .addComponent(firstNameField))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(emailLabel)
                            .addComponent(emailField))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(postalLabel)
                            .addComponent(postalField))))))
        .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addComponent(newButton)
            .addComponent(deleteButton)
            .addComponent(editButton)
            .addComponent(saveButton)
            .addComponent(cancelButton))));

        layout.linkSize(SwingConstants.HORIZONTAL, cancelButton, deleteButton, editButton, newButton, saveButton);

        layout.setVerticalGroup(layout.createParallelGroup()
            .addComponent(scrollpane)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(lastNameLabel)
                    .addComponent(lastNameField)
                    .addComponent(firstNameLabel)
                    .addComponent(firstNameField))
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(phoneLabel)
                    .addComponent(phoneField)
                    .addComponent(emailLabel)
                    .addComponent(emailField))
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(address1Label)
                    .addComponent(address1Field))
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(address2Label)
                    .addComponent(adress2Field))
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(cityLabel)
                    .addComponent(cityField))
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(stateLabel)
                    .addComponent(stateField)
                    .addComponent(postalLabel)
                    .addComponent(postalField))
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(countryLabel)
                    .addComponent(countryField))
                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(newButton)
                    .addComponent(cancelButton)
                    .addComponent(deleteButton)
                    .addComponent(editButton)
                    .addComponent(saveButton))));

        pack();
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddressBookDemo_GroupLayout().setVisible(true);
            }
        });
    }
}
