我的程序是
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);这两个,但是按钮的大小都没有变化。这个代码那里写错了?请大家指导一下,谢谢~
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);这两个,但是按钮的大小都没有变化。这个代码那里写错了?请大家指导一下,谢谢~
想改娈可以这样:JFrame j = new JFrame("kk");
Container cp = j.getContentPane();
cp.setLayout(null);
.......
jp.setBounds(100,100,100,100);//前两个是坐标,后两个是长与宽
试了 sysmaster(为什么我还不懂)的,虽然jp的位置和button的位置是变了,但是按钮的大小还是没有变化,难道真的按钮的大小不可以变吗?
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();
}
}