整个程序布局为this. GridLayout(5,1)
把整个分为5行 再在把这对应的5部分 定义
5个面版 每个面版在自定义比如最上面的一个
定义为Panel P1=new Panel();
           p1.setLayout(new GridLayout(1,2));下面的就面版就是P2,P3,P4,P5

解决方案 »

  1.   

    不行啊,GridLayout的每个格子大小都一样的呀
      

  2.   

    不用布局 就能做到了 
    setlayout(null)
      

  3.   

    //用GridBagLayoutimport javax.swing.*;
    import java.awt.*;public class Layout extends JFrame
    {
    Container cp;
    JLabel jlname,jladdress,jlnum,jlmailid;
    JTextField jtfname,jtfnum,jtfmailid;
    JScrollPane jspaddress;
    JTextArea jtaaddress;
    GridBagLayout gbl;
    GridBagConstraints gbc;

    public Layout()
    {
    setTitle("Layout Show");
    setBounds(20,20,350,250);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jlname=new JLabel("Customer Name:");
    jladdress=new JLabel("Current Address:");
    jlnum=new JLabel("Phone Number:");
    jlmailid=new JLabel("E-MAIL ID:");
    jtfname=new JTextField(15);
    jtaaddress=new JTextArea(3,15);
    jspaddress=new JScrollPane(jtaaddress);
    jspaddress.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jtfnum=new JTextField(15);
    jtfmailid=new JTextField(15);

    cp=getContentPane();
    gbc=new GridBagConstraints();
    gbc.fill=GridBagConstraints.BOTH;
    gbc.insets=new Insets(4,4,4,4);
    gbl=new GridBagLayout();

    cp.setLayout(gbl);
    gbc.gridx=0;
    gbc.gridy=0;
    gbc.gridheight=1;
    gbc.gridwidth=1;
    cp.add(jlname,gbc);
    gbc.gridx=1;
    cp.add(jtfname,gbc);
    gbc.gridx=0;
    gbc.gridy=1;
    cp.add(jladdress,gbc);
    gbc.gridx=1;
    gbc.gridheight=3;
    cp.add(jspaddress,gbc);
    gbc.gridx=0;
    gbc.gridy=4;
    gbc.gridheight=1;
    cp.add(jlnum,gbc);
    gbc.gridx=1;
    cp.add(jtfnum,gbc);
    gbc.gridx=0;
    gbc.gridy=5;
    cp.add(jlmailid,gbc);
    gbc.gridx=1;
    cp.add(jtfmailid,gbc);


    }

    public static void main(String[] args)
    {
    Layout l=new Layout();
    l.setVisible(true);
    }
    }
      

  4.   

    为什么不用borderlayout
    最下面的可以用一个panel其布局为gridlayout两行一列
      

  5.   

    用SetLayout(null)后,什么也显示不出来
    用GridBagLayot是可以的,但教师给的提示是用null layout,但就是不会用。
      

  6.   

    可以的 啊!!这句话是说定义1列5行你那图片上可以分成相等的5行啊this. GridLayout(5,1)整个程序布局为this. GridLayout(5,1)
    把整个分为5行 再在把这对应的5部分 定义
    5个面版 每个面版在自定义比如最上面的一个
    定义为Panel P1=new Panel();
               p1.setLayout(new GridLayout(1,2));下面的就面版就是P2,P3,P4,P5
      

  7.   


    GridBagLayout 就可以了。 楼主该揭帖了,呵呵。*******************************************************************
    import javax.swing.*;
    import java.awt.*;
    public class MyLayout extends JFrame {
      private JPanel jPanel1 = new JPanel();
      private JLabel label1 = new JLabel();
      private JLabel label2 = new JLabel();
      private JLabel label3 = new JLabel();
      private JLabel label4 = new JLabel();
      private JTextField textField1 = new JTextField();
      private JEditorPane editorPane1 = new JEditorPane();
      private JScrollPane scrollPane = new JScrollPane();
      private JTextField textField2 = new JTextField();
      private JTextField textField3 = new JTextField();
      private GridBagLayout gridBagLayout1 = new GridBagLayout();
      public static void main(String[] args) {
      }  public MyLayout() {
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      private void jbInit() throws Exception {
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        jPanel1.add(label2,  new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(24, 14, 70, 0), 14, 0));
        jPanel1.add(textField1,  new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(18, 25, 0, 25), 173, 0));
        jPanel1.add(scrollPane,  new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0
                ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(22, 26, 0, 25), 0, 62));
        jPanel1.add(label1,  new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 14, 0, 0), 15, 0));
        jPanel1.add(label4,   new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(18, 14, 25, 36), 13, 0));
        jPanel1.add(label3,  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(34, 14, 0, 0), 23, 0));
        jPanel1.add(textField2,  new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(30, 22, 0, 25), 173, 0));
        jPanel1.add(textField3,  new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0
                ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(19, 23, 25, 25), 173, 0));
        scrollPane.getViewport().add(editorPane1, null);
        jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
        jPanel1.setLayout(gridBagLayout1);
        label1.setText("CustomerName:");
        label2.setText("Current Address:");
        label3.setText("PhoneNumber:");
        label4.setText("Email ID:");
        this.getContentPane().add(jPanel1, BorderLayout.CENTER);
      }
    }***********************************************************************