GridBagLayout gridbag=new GridBagLayout();
-->
GridLayout gridbag=new GridLayout();

解决方案 »

  1.   

    想知道为何使用一般的布置器GridBagLayout  GridLayout为何不行呢?
      

  2.   

    是因为weightx和weighty没有设置!import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ManagerAgentFrame extends Frame{
    Panel leftPanel=new Panel();
    Panel rightPanel=new Panel();
    Color color1 =new Color(255,0,0);
    Color color2 =new Color(255,250,0);
    ManagerAgentFrame(){
    setSize(550,400);
    setResizable(false);
    leftPanel.setBackground(color1);
    GridBagLayout gridbag=new GridBagLayout();
    GridBagConstraints gbc=new GridBagConstraints();
    setLayout(gridbag);

    gbc.fill=GridBagConstraints.BOTH;
    gbc.weightx=1.0;
    gbc.weighty=1.0;
    add(leftPanel,gbc);

        rightPanel.setBackground(color2);
       
    gbc.weightx=2.0;
            add(rightPanel,gbc);
    }
    public static void main(String[] args){
    ManagerAgentFrame frame=new ManagerAgentFrame();
    frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
            });               
             frame.setVisible(true);       
            }
    }