GridBagLayout confusion

From: Kurt (kharless_at_qwest.net)
Date: 08/26/04


Date: 25 Aug 2004 15:52:17 -0700

Greetings,

Resizing components added in a GridBagLayout doesn't seem to affect
the actual size of the component. Where am I lost?

Snippet below;

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

public class Demo
{
    public static void main(String[] args)
    {
       Window win = new Window();
    }
}
    
class Window extends JFrame implements ActionListener
{
    JButton bt1 = new JButton("Start Test 1");
    JButton bt2 = new JButton("Start Test 2");
    
    public Window()
    {
        super("Window Title");
        setSize(400,100);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        Container ca = getContentPane();
        ca.setBackground(Color.white);
        GridBagLayout gbl = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        ca.setLayout(gbl);
                
        bt1.addActionListener(this);
        bt2.addActionListener(this);
        
        gbc.gridx = 1;
        gbc.gridy = 1;
        ca.add(bt1,gbc);
        
        gbc.gridx = 2;
        gbc.gridy = 1;
        gbc.gridheight = 400;
        gbc.gridwidth = 400;
        bt2.setSize(400,400);
        ca.add(bt2,gbc);
        
        setContentPane(ca);
    }
    
    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource()==bt1)
            System.out.println("You Pressed button 1");
        else
            System.out.println("You Pressed button 2");
    }
 }