0% found this document useful (0 votes)
42 views

Gridbaglayout: The Most Flexible and Complex Layout Manager

GridBagLayout is a flexible and complex layout manager that places components in a grid of rows and columns, allowing components to span multiple rows or columns. It uses gridbag constraints to specify the size, position, and padding of each component. Constraints include gridx, gridy to specify position, gridwidth and gridheight if a component spans cells, and weightx and weighty to distribute extra space among rows and columns.

Uploaded by

Geay Peter
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Gridbaglayout: The Most Flexible and Complex Layout Manager

GridBagLayout is a flexible and complex layout manager that places components in a grid of rows and columns, allowing components to span multiple rows or columns. It uses gridbag constraints to specify the size, position, and padding of each component. Constraints include gridx, gridy to specify position, gridwidth and gridheight if a component spans cells, and weightx and weighty to distribute extra space among rows and columns.

Uploaded by

Geay Peter
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

GridBagLayout

The most flexible and complex layout


manager
GridBagLayout
• It is very flexible and very complex layout manager
•  A GridBagLayout places components in a grid of rows
and columns, allowing specified components to span
multiple rows or columns.
• Not all rows necessarily have the same height. Similarly,
not all columns necessarily have the same width.
• GridBagLayout places components in rectangles (cells) in
a grid, and then uses the components' preferred sizes to
determine how big the cells should be.
• This uses gridbaglayout with three columns and three rows
• The rows have different heights with the top row being thinner,
and the middle row being thicker
• The button in the middle row spans the three columns

• The way the program specifies the size and position


characteristics of its components is by specifying constraints for
each component.
Specifying Constraints

• gridx, gridy
– Specify the row and column at the upper left of the
component.
– The leftmost column has address gridx=0 and the top
row has address gridy=0.
• gridwidth, gridheight
– Specify the number of columns (for gridwidth) or rows
(for gridheight) in the component's display area.
– GridBagConstraints.REMAINDER specifies that the
component is the last one in its row (for gridheight) or
is the last one its column (for gridwidth)
Specifying the constraints (…)
• fill
– Used when the component's display area is larger
than the component's requested size to determine
whether and how to resize the component.
– Valid values include 
• NONE - the default
• HORIZONTAL - make the component wide enough to fill
its display area horizontally, but do not change its
height
• VERTICAL - make the component tall enough to fill its
display area vertically, but do not change its width),
• BOTH - make the component fill its display area entirely
Specifying the constraints (…)
• ipadx, ipady
– Specifies the internal padding: how much to add
to the size of the component.
– The default value is zero.
– The width of the component will be at least its
minimum width plus ipadx*2 pixels, since the
padding applies to both sides of the component.
– the height of the component will be at least its
minimum height plus ipady*2 pixels
• insets
– Specifies the external padding of the component -- the minimum
amount of space between the component and the edges of its
display area.
– The value is specified as an Insets object.
– By default, each component has no external padding.
• Anchor
– Used when the component is smaller than its display area to
determine where (within the area) to place the component.
– Valid values are CENTER (the default), PAGE_START, PAGE_END,
LINE_START, LINE_END, FIRST_LINE_START,FIRST_LINE_END, LAST_
LINE_END, and LAST_LINE_START.
• weightx, weighty
– Used to distribute space among columns (weightx)
and among rows (weightx)
– Weights are good especially during resizing the
container
– The weights range from 0.0 (the default) to 1.0.
weight 0.0 means any extra space is put between its
grid of cells and edges of the container. Larger
numbers indicate that the component's row or
column should get more space.

You might also like