标题:网格布局显示不对,困扰我好几天了.
只看楼主
嶄ぎ儱
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2007-4-21
 问题点数:0 回复次数:3 
网格布局显示不对,困扰我好几天了.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GriBagLayout extends JFrame
{
void buildCo(GridBagConstraints gbc, int gx,int gy,int gw,int gh,int wx,int wy)
{
gbc.gridx=gx;
gbc.gridy=gy;
gbc.gridwidth=gw;
gbc.gridheight=gh;
gbc.weightx=wx;
gbc.weighty=wy;
}
public GriBagLayout()
{
super("网格布局");
setSize(290,110);
GridBagLayout gridbag=new GridBagLayout();
GridBagConstraints constraints=new GridBagConstraints();
JPanel pan=new JPanel();
pan.setLayout(gridbag);
//Name label
buildCo(constraints,0,0,1,1,10,40);
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.EAST;
JLabel label=new JLabel("Name:",JLabel.LEFT);
gridbag.setConstraints(label,constraints);
pan.add(label);
//Name text field
buildCo(constraints,1,0,1,1,90,0);
constraints.fill=GridBagConstraints.HORIZONTAL;
JTextField text=new JTextField();
gridbag.setConstraints(text,constraints);
pan.add(text);
// passwore label
buildCo(constraints,0,1,1,1,0,40);
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.EAST;
JLabel labe=new JLabel("password:",JLabel.LEFT);
pan.add(labe);
// password text
buildCo(constraints,1,1,1,1,0,0);
constraints.fill=GridBagConstraints.HORIZONTAL;
// constraints.anchor=GridBagConstraints.CENTER;
JPasswordField tex=new JPasswordField();
tex.setEchoChar('*');
gridbag.setConstraints(tex,constraints);
pan.add(tex);
//OK button
buildCo(constraints,0,2,2,1,0,20);
constraints.fill=GridBagConstraints.NONE;
constraints.anchor=GridBagConstraints.CENTER;
JButton button=new JButton("OK");
gridbag.setConstraints(button,constraints);
pan.add(button);
//content pane
setContentPane(pan);
}
public static void main(String[] args)
{
GriBagLayout grib=new GriBagLayout();
ExitWindow exit=new ExitWindow();
grib.addWindowListener(exit);
grib.show();
}
}
class ExitWindow extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
为什么出现这样的图形,我好像没有写错啊!!!! 怎么到现在还没有帮我解决啊!!!!!

[此贴子已经被作者于2007-5-25 8:32:17编辑过]

搜索更多相关主题的帖子: 网格 困扰 
2007-05-24 18:22
songwei20000
Rank: 1
等 级:新手上路
帖 子:82
专家分:0
注 册:2007-4-23
得分:0 
网格那用这么麻烦啊!this.setlayout(new GridLayout(int几行,int几列,int行间距,int列间距));
2007-05-24 18:37
嶄ぎ儱
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2007-4-21
得分:0 
我是练习一些类和方法的用法.因为我很多不熟.

别人不给你机会,自己去创造机会.
2007-05-24 18:40
w289592467
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2007-4-19
得分:0 
GridBagLayout gridbag=new GridBagLayout();
不是那个GridLayout我也觉得GridBagLayout gridbag=new GridBagLayout();难。。可能我刚学
2007-05-24 18:56



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




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

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