/*** Grid layout manager of java; * The grid layout manager divides a form into a table. You can specify rows and columns of the table when creating the grid layout manager. By default, * is added to the control in the form from left to right, from top to bottom, and each control is filled with the entire cell, that is, changing the size of the * Form widget also changes the size. * @ Author gao */package com. gao; import java. awt. gridLayout; import javax. swing. JButton; import javax. swing. JFrame; import javax. swing. JPanel; import javax. swing. border. extends; public class extends JFrame {private JPanel contentPane; private JButton button1; private JButton button2; private JButton button3; private JButton button4; private JButton button5; private JButton button6; private JButton button7; private JButton button8; private JButton button9; public GridLayoutDemo () {contentPane = new JPanel (); contentPane. setBorder (new EmptyBorder (5, 5, 5); // you can specify the upper, left, lower, and right sides of the Panel. setContentPane (contentPane); contentPane. setLayout (new GridLayout (3, 3, 5); button1 = new JButton ("button 1"); button2 = new JButton ("button 2 "); button3 = new JButton ("button 3"); button4 = new JButton ("button 4"); button5 = new JButton ("button 5 "); button6 = new JButton ("button 6"); button7 = new JButton ("button 7"); button8 = new JButton ("button 8 "); button9 = new JButton ("button 9"); contentPane. add (button1); contentPane. add (button2); contentPane. add (button3); contentPane. add (button4); contentPane. add (button5); contentPane. add (button6); contentPane. add (button7); contentPane. add (button8); contentPane. add (button9); this. setTitle ("border layout"); this. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); this. setBounds (100,100,450,300); this. setVisible (true);} public static void main (String [] args) {GridLayoutDemo example = new GridLayoutDemo ();}}
Running result:
If you are interested, you can change the size.
Check the effect.