import javax.swing.*;
import java.awt.*;
// Demo
public class JpanelTest extends JFrame {
public JpanelTest() {
this.setLayout(new GridLayout(2, 1,10, 10));
JPanel[] p = { new JPanel(new GridLayout(1, 3, 10, 10)),
new JPanel(new GridLayout(1, 2, 10, 10)),
new JPanel(new GridLayout(1, 2, 10, 10)),
new JPanel(new GridLayout(2, 1, 10, 10))};
for (int i = 1; i < 10; i++) {
if (i < 4) {
p[0].add(new JButton("" + i));
}else if (i < 6) {
p[1].add(new JButton("" + i));
}else if (i < 8) {
p[2].add(new JButton("" + i));
}else {
p[3].add(new JButton("" + i));
}
}
for (int i = 0; i < 4; i++) {
this.add(p[i]);
}
this.setSize(350, 200);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JpanelTest();
}
}