Gridbaglayout: The Most Flexible and Complex Layout Manager
Gridbaglayout: The Most Flexible and Complex Layout Manager
• 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.