版主,你的意思是说那个getContentPane().setLayout()在1.5JDK设置那我用的也是1.5的JDK,都是要设置那个,我这里有个例子
import javax.swing.JFrame;
import java.awt.FlowLayout;
import javax.swing.JButton;
class UseFlowLayout extends JFrame{
JButton jButton1=new JButton("按键一");
JButton jButton2=new JButton("按键二");
JButton jButton3=new JButton("按键三");
JButton jButton4=new JButton("按键四");
JButton jButton5=new JButton("按键五");
FlowLayout flowLayout1=new FlowLayout(FlowLayout.CENTER);
UseFlowLayout(){
super("流式布局示例");
setSize(300,200);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.getContentPane().setLayout(flowLayout1);
this.getContentPane().add(jButton1);
this.getContentPane().add(jButton2);
this.getContentPane().add(jButton3);
this.getContentPane().add(jButton4);
this.getContentPane().add(jButton5);
setResizable(true);
setVisible(true);
}
如果我不用this.getContentPane().setLayout(flowLayout1);就只能显示jButton5
----------------解决方案--------------------------------------------------------
你可以
this.setLayout(flowLayout1);
this.add(jButton1);
...
this.add(jButton5);
----------------解决方案--------------------------------------------------------
无论你省还是不省 getContentPane,
因为JFrame默认是BorderLayout,你想改为FLowLayout,你就得setLayout
----------------解决方案--------------------------------------------------------
哦,谢谢版主,我试过了,你说得没错!我还真不知道原来这样可以省的!
----------------解决方案--------------------------------------------------------
呵呵,以后可以记得了
----------------解决方案--------------------------------------------------------