“`标签:Java,网格,new,swing,GridLayout,java,public From: https://blog.51cto.com/u_6778639/6096166
package com.js;
import java.awt.*;
import javax.swing.*;
public class Java_3_swing_7_GridLayout extends JFrame{
public Java_3_swing_7_GridLayout(){
Container c = getContentPane();
// 设置容器使用网格布局管理器,设置7行3列的网格
setLayout(new GridLayout(7,3,5,5));
for(int i = 0; i< 20; i++){
c.add(new JButton(“button”+i));
}
setSize(300,300);
setTitle(“这是一个使用网格布局管理器的窗体”);
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
}public static void main(String[] args) {
// TODO 自动生成的方法存根
new Java_3_swing_7_GridLayout();
}}
“`