You are on page 1of 2

difference :

"GridLayout class lays all components in a rectangular grid like structure of


container. The container is divided into an equal sized rectangles and each
component is placed inside a rectangle.
The GridBagLayout class is a flexible layout manager that aligns components
vertically and horizontally, without requiring that the components be of the same
size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells,
with each component occupying one or more cells, called its display area.
Each component managed by a GridBagLayout is associated with an instance of
GridBagConstraints. The constraints object specifies where a component's display
area should be located on the grid and how the component should be positioned
within its display area. In addition to its constraints object, the GridBagLayout
also considers each component's minimum and preferred sizes in order to determine a
component's size."

constructors of gridbaglayout

GridBagLayout class is a flexible layout manager. It is used to aligns the


components horizontally, vertically or along their baseline. It doesn�t require the
components of the same size. Each GridBagLayout object manages a rectangular grid
of cells, dynamic with each component occupying one or more cells, called its
display area. GridBagLayout components are associated with the instance of
GridBagConstraints. These constraints are used to define the component�s display
area and their positions. In addition to its constraints object, the GridBagLayout
also considers each component�s minimum and preferred sizes in order to determine a
component�s size. GridBagLayout components are also arranged in the rectangular
grid but can have different sizes and can occupy the multiple rows or columns.
Constructor:
GridBagLayout(): It is used to creates a grid bag layout manager.

name of default layout for different container

Containers which uses Border Layout as their default are: window, Frame and Dialog
classes.
Every container, by default, has a layout manager. For Panels, including Applets,
the default layout manager belongs to the class FlowLayout. For Windows, the
default layout manager is a BorderLayout. You can change the layout manager of a
container using its setLayout(LayoutManager) method
For a java.applet.Applet, the default layout manager is FlowLayout. For the content
pane of a javax.swing.JApplet, the default layout manager is a BorderLayout

flow layout gap


This constructor creates a FlowLayout using default settings: center alignment with
a horizontal and vertical gap of five pixels. The gap is the space between the
different components in the different directions. By default, there will be five
pixels between components.

use of insets in borderlayout

Every component has a set of insets. Insets specify the widths of the component's
margins. Insets include:
top inset
left inset
bottom inset
right inset
For example, a frame's insets include a top inset that compensates for the frame's
titlebar, and insets all around that compensate for the border (which we can use to
resize the frame).
A panel contained within a frame has its own insets. Indeed, any component has its
own insets.

Layout managers are supposed to respect a container's insets and never lay out a
component in the inset margins. The layout managers supplied with the JDK all
respect this. If you write a layout manager, you should write it to respect
insets, too.
// insets (top, left, bottom, right).
public Insets getInsets()
{
return new Insets(5, 10, 15, 20);
}

You might also like