http://www3.ccw.com.cn/club/essence/200305/16449.htm

解决方案 »

  1.   

    比如改成如下的:import java.awt.event.*;
    import javax.swing.*;public class UsingHtml implements ActionListener{
    public void actionPerformed(ActionEvent e){ }
    public static void main(String[] args){
    JFrame f = new JFrame("Test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JButton("a"));
    f.pack();
    f.setVisible(true);
    }
    }
    你再试试。是不是明白了?具体可以看看 JDK 的 docs。
      

  2.   

    public void pack()
    Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated. 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    java.awt.Window.pack()
      

  3.   

    pack()方法是自动适应窗口的布局,使用它
    setSize()就失去作用了,它是更具控件的大小
    进行布局的
      

  4.   

    建议楼主多查JDK的帮助文档,更有收获.
      

  5.   

    pack()方法是自动适应窗口的布局,它是更具控件的大小
    进行布局的,他的优先级高于setSize(),所以这里窗口就不是200*200的