标题:[求助]网格块布局迷惑
取消只看楼主
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
结帖率:71.43%
 问题点数:0 回复次数:0 
[求助]网格块布局迷惑

import java.awt.*;
import javax.swing.*;
public class text extends JFrame{
public static void main(String[] args){
new text();
}
public text(){
super("邮件窗口");
Label receiveLabel=new Label("收件人");
Label ccLabel=new Label("抄送");
Label subjectLabel=new Label("主题");
Label accessoryLabel=new Label("附件");

TextField receiveField=new TextField();
TextField ccField=new TextField();
TextField subjectField=new TextField();

TextArea accessoryArea=new TextArea(1,40);
TextArea mailArea=new TextArea(8,40);
this.setLayout(new java.awt.GridBagLayout());
GridBagConstraints gridBag=new GridBagConstraints();
gridBag.fill=GridBagConstraints.HORIZONTAL;
gridBag.weightx=0;
gridBag.weighty=0;


receiveLabel.setFont(new Font("Alias",Font.BOLD,16));
this.add(receiveLabel,gridBag,0,0,1,1);
ccLabel.setFont(new Font("Alias",Font.BOLD,16));
this.add(ccLabel,gridBag,0,1,1,1);
subjectLabel.setFont(new Font("Alias",Font.BOLD,16));
this.add(subjectLabel,gridBag,0,2,1,1);
accessoryLabel.setFont(new Font("Alias",Font.BOLD,16));
this.add(accessoryLabel,gridBag,0,3,1,1);

gridBag.weightx=100;
gridBag.weighty=0;

this.add(receiveField,gridBag,1,0,1,1);
this.add(ccField,gridBag,1,1,2,1);
this.add(subjectField,gridBag,1,2,2,1);
accessoryArea.setEditable(false);
this.add(accessoryArea,gridBag,1,3,2,1);

gridBag.fill=GridBagConstraints.BOTH;
gridBag.weightx=100;
gridBag.weighty=100;
this.add(mailArea,gridBag,0,4,3,1);

this.setLocation(120,150);
this.setSize(300,300);
this.setDefaultCloseOperation(3);
this.setVisible(true);
}
private void add(Component c,GridBagConstraints gbc,int x,int y,int w,int h){
gbc.gridx=x;
gbc.gridy=y;
gbc.gridheight=h;
gbc.gridwidth=w;
add(c,gbc);
}
}
在这个程序中:
gridx,gridy,gridheight,gridwidth,weigthx,weigthy
如何理解,我已经看过帮助,但看不懂,希望各位详细解释。

搜索更多相关主题的帖子: 网格 
2007-10-27 16:26



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-181214-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.912981 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved