A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 饶正林 中级黑马   /  2013-4-29 16:00  /  1047 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class GridBagLayoutDemo
  5. {
  6. public GridBagLayoutDemo()
  7. {
  8.   JFrame j=new JFrame("我的GridBagLayoutDemo面板");
  9.   GridBagLayout g=new GridBagLayout();
  10.   j.getContentPane().setLayout(g);
  11.   GridBagConstraints c;
  12.   int gridx,gridy,gridwidth,gridheight,anchor,fill,ipadx,ipady;
  13.   double weightx,weighty;
  14.   Insets inset;
  15.   JButton b=new JButton("你好呀!");
  16.   gridx=0;
  17.   gridy=0;
  18.   gridwidth=1;
  19.   gridheight=1;
  20.   weightx=10;
  21.   weighty=1;
  22.   anchor=GridBagConstraints.CENTER;
  23.   fill=GridBagConstraints.HORIZONTAL;
  24.   inset=new Insets(0,0,0,0);
  25.   ipadx=0;
  26.   ipady=0;
  27.   c=new GridBagConstraints(gridx,gridy,gridwidth,gridheight,weightx,weighty,anchor,fill,inset,ipadx,ipady);
  28.   g.setConstaints(b,c);//为何这有错呢?
  29.   j.getContentPane().add(b);
  30.   j.pack();
  31.   j.setVisible(true);
  32.   j.addWindowListener(new WindowAdapter()
  33.   {
  34.    public void windClosing(WindowEvent e)
  35.    {
  36.     System.exit(0);
  37.    }
  38.   }
  39.   );
  40. }
  41. public static void main(String[] args)
  42. {
  43.   new GridBagLayout();
  44. }
  45. }

  46. <p> </p>
复制代码
设置约束,这里错在哪里?

2013-04-29_155811.png (3.31 KB, 下载次数: 0)

2013-04-29_155811.png

评分

参与人数 1技术分 +1 收起 理由
黄玉昆 + 1

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马