Each widget has a natural height and a natural width (for example, jbutton height and width are determined by the text length), and a display area (Green Box, blue box, and red box in the figure ), the natural width and height of jtextarea are the width and height of the display area. For example
The height of the display control occupied by each widget in one row is the same. The width of each control in one column is the same. For the preceding three controls (two jbuttons and one jtextarea), set constraints. fill
= Gridbagconstraints. Vertical; in this way, you can see their display areas:
Extra horizontal space (extra horizontal space), that is, H1 + H2 in Figure 1
VariableWidthxIs to allocate additional horizontal space according to the widthx value of each control in a row. For example, set the first control widthx to 8 and the second widthx to 0, if the third widthx is set to 2, the result is as follows:
(Set constraints. Fill = gridbagconstraints. Both to conveniently observe the display space of each control)
We can see that H1 + H2 is divided by the first and third controls according to the ratio of. If width is 0, no additional space is allocated.
Widthy.
Gridx,Gridy
The cell where the left edge line of the control (container from left to right) is located, the cell where the edge line on the control is located, and the green control's gridx and gridy are () Black controls are)
The default value is-1, which is placed close to the previous or previous control.
Gridwidth, gridheight
The number of cells that the control occupies in one row and the number of cells in one column. 0 indicates that all cells in one row and one column are occupied.
Fill
When the display area of the control is larger than the natural area, it determines how to fill it. Horizontal horizontal fill, vertical fill, both horizontal fill, vertical fill, none do not fill.
Insets: insets
The size of the blank area on the edge of the widget and the table space.