What is GridBagLayout - Java Swing

Java examples for Swing:GridBagLayout

Introduction

The GridBagLayout lays out components in a grid of rectangular cells arranged in rows and columns.

The following snippet of code creates an object of the GridBagLayout class and sets it as the layout manager for a JPanel:

import java.awt.GridBagLayout;

import javax.swing.JPanel;

public class Main {
  public static void main(String[] argv) throws Exception {
    // Create a JPanel container
    JPanel panel = new JPanel();

    // Set GridBagLayout as the layout manager for the JPanel
    GridBagLayout gridBagLayout = new GridBagLayout();
    panel.setLayout(gridBagLayout);
  }
}

Related Tutorials