黑马程序员技术交流社区
标题:
设置约束中的错在哪里?
[打印本页]
作者:
饶正林
时间:
2013-4-29 16:00
标题:
设置约束中的错在哪里?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GridBagLayoutDemo
{
public GridBagLayoutDemo()
{
JFrame j=new JFrame("我的GridBagLayoutDemo面板");
GridBagLayout g=new GridBagLayout();
j.getContentPane().setLayout(g);
GridBagConstraints c;
int gridx,gridy,gridwidth,gridheight,anchor,fill,ipadx,ipady;
double weightx,weighty;
Insets inset;
JButton b=new JButton("你好呀!");
gridx=0;
gridy=0;
gridwidth=1;
gridheight=1;
weightx=10;
weighty=1;
anchor=GridBagConstraints.CENTER;
fill=GridBagConstraints.HORIZONTAL;
inset=new Insets(0,0,0,0);
ipadx=0;
ipady=0;
c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,fill,inset,ipadx,ipady);
g.setConstaints(b,c);//为何这有错呢?
j.getContentPane().add(b);
j.pack();
j.setVisible(true);
j.addWindowListener(new WindowAdapter()
{
public void windClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
new GridBagLayout();
}
}
<p> </p>
复制代码
设置约束,这里错在哪里?
2013-04-29_155811.png
(3.31 KB, 下载次数: 0)
下载附件
2013-4-29 15:58 上传
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2