tBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); // contentPane.setLayout(new GridLayout());// 设置网格布局,默认是单行多列 contentPane.setLayout(new GridLayout(3, 3, 10, 10));// 设置网格布局 3行3列 for (int i = 0; i < 8; i++) { JButton btn = new JButton("btn"+(i+1)); contentPane.add(btn); } } }
|