//This window uses GridBagLayout layout manager

import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.*;


public class Awindow9 
{
    private static final long versionId = 1;
    private JLabel      searchLabel;
    private JTextField  searchField;
    private JButton     searchButton;
    private JTextField  searchResult;
    private JScrollPane searchScroll;
    
    public static void main(String[] args)
    {
        Awindow9 w = new Awindow9();
        w.start();
    }

    public void start()
    {
        JFrame frame = new JFrame("Address Book");
        frame.setSize(640,300);
        frame.setLocationRelativeTo(null);				//if null, center the window relative to screen
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
        GridBagLayout      layoutMgr = new GridBagLayout();
        GridBagConstraints layout    = new GridBagConstraints();	//configuration constants for GridBagLayout 
                
        JPanel panel = new JPanel(layoutMgr);				//create JPanel and use requested layout manager

        Insets padding = new Insets(3,3,3,3);				//set padding top/left/bottom/right
        layout.insets  = padding;					
        
        searchLabel  = new JLabel("Enter a last name: ");
        searchField  = new JTextField(20);
        searchButton = new JButton("Search");
        searchResult = new JTextField();        
        searchScroll = new JScrollPane(searchResult);			//make the search result field scrollable
        
        layout.gridy = 0;						//grid position y=0 (vertical) 
        layout.gridx = 0;						//grid position x=0 (horizontal) 
        panel.add(searchLabel, layout);					//place this component at x=0/y=0 

        layout.gridx++;							//grid position x=1 (horizontal)
        layout.fill = GridBagConstraints.HORIZONTAL;			//if field is smaller than area, fill horizontaly
        layout.weightx = 1;						//give all the extra space to this component
        panel.add(searchField, layout);					//place this component at x=1/y=0

        layout.gridx++;							//grid position x=2 (horizontal)
        layout.fill = GridBagConstraints.NONE;				//if field smaller than area, do not fill
        layout.weightx = 0;						//do not give this field any additional space       
        panel.add(searchButton, layout);				//place this component at x=2/y=0 
        
//      layout.gridy++;							//grid position y=1 (vertical) 
//      layout.gridx = 0;						//grid position x=0 (horizontal) 
//      layout.gridwidth  = 3;						//component should take up 3 columns 
//      layout.gridheight = GridBagConstraints.REMAINDER;		//component should take up 3 columns 
//      layout.fill       = GridBagConstraints.BOTH;			//if field is smaller than area, fill horizontaly
//      layout.weightx = 1;						//give all the extra space to this component
//      panel.add(searchScroll, layout);				//place this component at x=2/y=0 

        frame.add(panel, BorderLayout.NORTH);				//add the panel to top of frame
        frame.add(searchScroll);					//add the scrollable result field

        frame.setVisible(true);
    }        
}