How does JAVAswing make buttons and labels enlarge with the enlargement of the window, and the typesetting remains the same?

Use gridbaglayout layout.

Use this layout to store button and label components in JPanel.

The layout is a bit cumbersome. Please leave a message if you don't understand.

The following is a description of the layout parameters of gridbaglayout. You can use it.

Gridx-the distance between the left edge of the component and the left part of the grid. The default value is a relative value.

Gridy- the distance between the top edge of the component and the top of the grid. The default value is a relative value.

Grid width-the horizontal width of the component. The default value is 1.

Grid height-the vertical height of the component; The default value is 1.

Ipadx- the horizontal spacing between components. The width of a component is the minimum width of the component plus the ipadx value. The default value is 0.

Ipady- vertical spacing between components. The height of a component is the minimum height of the component plus the ipady value. The default value is 0.

Weightx-When the window becomes larger, the proportion of each component becomes larger in the horizontal direction. The default value is 0.

Weight-When the window becomes larger, the proportion of each component becomes larger in the vertical direction. The default value is 0.

Fill-The component is smaller than the display area and can be used to control the behavior of the component. Controls whether the component is filled vertically, horizontally or bi-directionally. The default value is none.

Insert-refers to the size of the blank area around the component and the display area (top, left, bottom and right). The default value is newInsets (0 0,0,0).

Anchor-The component is smaller than the display area, which tells the layout manager where the component is in the tablespace. The default value is

Center.

After modifying gridwidth and gridheight, you must remember to modify the fill attribute accordingly, otherwise the size displayed by the component will still be the original size.

Possible values of gridx and gridy

RELATIVE will be placed to the right or below the previous component.

Possible values of gridwidth and gridheight.

RELATIVE specifies the component as the penultimate component in its row or column.

Components created by the REMAINDER will expand from the starting point of creation to the limit allowed by the container.

Possible padding values

None: Do not resize the component.

Horizontal: Widens the component to fill the display area horizontally without changing the height. VERTICAL: Raise the component so that it vertically fills the display area, but does not change the width. BOTH: makes the component completely fill its display area.