为什么一定要先写setSize()然后再写setVisible(),否则添加的控件就无法显示。
如:import java.awt.*;
import javax.swing.*;
public class MyLabel extends JFrame
{
JLabel label=new JLabel("MYLABEL");
public MyLabel()
{
super("MyLabel");
Container container=this.getContentPane();
container.setLayout(new BorderLayout());
container.add(label,BorderLayout.CENTER);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String args[])
{
MyLabel mylabel=new MyLabel();
mylabel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}如果将其中的
{ this.setSize(300,300);
this.setVisible(true); }写成
{ this.setVisible(true);
this.setSize(300,300); }
则添加的JLabel控件就不会显示。
请问这是什么原因?
请大家帮忙。
如:import java.awt.*;
import javax.swing.*;
public class MyLabel extends JFrame
{
JLabel label=new JLabel("MYLABEL");
public MyLabel()
{
super("MyLabel");
Container container=this.getContentPane();
container.setLayout(new BorderLayout());
container.add(label,BorderLayout.CENTER);
this.setSize(300,300);
this.setVisible(true);
}
public static void main(String args[])
{
MyLabel mylabel=new MyLabel();
mylabel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}如果将其中的
{ this.setSize(300,300);
this.setVisible(true); }写成
{ this.setVisible(true);
this.setSize(300,300); }
则添加的JLabel控件就不会显示。
请问这是什么原因?
请大家帮忙。
反过来则是不圈地皮就要盖楼,不知道会发生什么。