你把frame.setVisible(true);这一句移到最后一句,就象这样:
12345678910111213141516import java.awt.GridLayout;import javax.swing.JButton;import javax.swing.JFrame;public class Test9 { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(640, 480); GridLayout grid = new GridLayout(GlobalConfig.ROW,GlobalConfig.COLUMN); frame.setLayout(grid); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for (int i = 0; i < 81; i++) { frame.add(new JButton("" + i)); } frame.setVisible(true); //这一句移到这里 }}
就能正常显示了.
温馨提示:答案为网友推荐,仅供参考