A GridBagLayout Used in Its Simplest Form. - Java Swing

Java examples for Swing:GridBagLayout

Description

A GridBagLayout Used in Its Simplest Form.

Demo Code

import java.awt.Container;
import java.awt.GridBagLayout;

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

public class Main {
  public static void main(String[] args) {

    JFrame frame = new JFrame("GridBagLayout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridBagLayout());

    for (int i = 1; i <= 9; i++) {
      contentPane.add(new JButton("Button " + i));
    }/*w  w w .jav a  2  s  . co  m*/
    frame.pack();
    frame.setVisible(true);
  }
}

Related Tutorials