import java.awt.GridLayout;Output
import javax.swing.JButton;
导入 javax.swing.JFrame;
import javax.swing.JPanel;
公共类 GridLayoutExample 扩展 JFrame{
GridLayout grid = new GridLayout(3, 2);
public GridLayoutExample(){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250,250);
frame.setVisible(true);
JPanel 面板 = new JPanel();
frame.setContentPane(面板);
panel.setLayout(grid);
panel.add(new JButton(1”));
panel.add(new JButton(2”));
panel.add(new JButton(3”));
panel.add(new JButton(4”));
panel.add(new JButton(5”));
panel.add(new JButton(6”));
}
public static void main(String[] args) {
new GridLayoutExample();
}
}
public gridLayout(int line, int col, int hgap, int vgap);
grid.setHgap(10);
grid.setVgap(15);
Please disable your ad blocker and refresh the window to use this website.