Test Grid Layout with nine buttons - Java Swing

Java examples for Swing:GridLayout

Description

Test Grid Layout with nine buttons

Demo Code

import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JFrame {

  public Main() {
    super("Bunch");
    setSize(260, 260);/*w  w w  .  j  ava2s .  c  o  m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel pane = new JPanel();
    GridLayout family = new GridLayout(3, 3, 10, 10);
    pane.setLayout(family);
    JButton a = new JButton("A");
    JButton b = new JButton("B");
    JButton c = new JButton("C");
    JButton d = new JButton("D");
    JButton e = new JButton("E");
    JButton f = new JButton("F");
    JButton g = new JButton("G");
    JButton h = new JButton("H");
    JButton i = new JButton("I");
    pane.add(a);
    pane.add(b);
    pane.add(c);
    pane.add(d);
    pane.add(e);
    pane.add(f);
    pane.add(g);
    pane.add(h);
    pane.add(i);
    add(pane);
    setVisible(true);
  }

  public static void main(String[] arguments) {
    Main frame = new Main();
  }
}

Related Tutorials