我的程序是
public static void main(String args[]) {
    JFrame j = new JFrame("kk");
    Container cp = j.getContentPane();
    JPanel jp = new JPanel();
    JButton j1 = new JButton("first");
    JButton j2 = new JButton("firstfirst");
    j1.setSize(200,200);
    j2.setSize(200,200);
    jp.add(j1);
    jp.add(j2);
    cp.add(jp);
    j.setSize(400,400);
    j.show();
  }
可是不管我怎么设置j1.setSize(200,200);j2.setSize(200,200);这两个,但是按钮的大小都没有变化。这个代码那里写错了?请大家指导一下,谢谢~

解决方案 »

  1.   

    用button.setBounds(new Rectangle(20,20,30,30));方法
      

  2.   

    使用了布局生,控件的大小是无法改变的。
    想改娈可以这样:JFrame j = new JFrame("kk");
        Container cp = j.getContentPane();
        cp.setLayout(null);
       .......
        jp.setBounds(100,100,100,100);//前两个是坐标,后两个是长与宽
      

  3.   

    我试了 xtaotao(淘淘)的,好像加了这句话后按钮的大小还是没有改变
    试了 sysmaster(为什么我还不懂)的,虽然jp的位置和button的位置是变了,但是按钮的大小还是没有变化,难道真的按钮的大小不可以变吗?
      

  4.   

    在你的代码基础上改的,试试import javax.swing.*;
    import java.awt.*;class test{
    public static void main(String args[]) {
        JFrame j = new JFrame("kk");
        Container cp = j.getContentPane();
        JPanel jp = new JPanel();
        jp.setLayout(null);
        JButton j1 = new JButton("first");
        JButton j2 = new JButton("firstfirst");
        j1.setBounds(new Rectangle(20,20,120,30));
        j2.setBounds(new Rectangle(20,120,120,30));
        jp.add(j1);
        jp.add(j2);
        cp.add(jp);
        j.setSize(400,400);
        j.show();
      }
    }