How to use gridbaglayout, the most important layout manager in Java

Gridbaglayout is one of the most important layout managers in Java. It can make very complex layouts. It can be said that gridbaglayout must be learned well,

The gridbaglayout class is a flexible layout manager that can align components vertically, horizontally, or along their baselines without requiring the same size of components.

Each gridbaglayout object maintains a dynamic rectangular cell grid, and each component occupies one or more such cells, which are called display areas.

Here is a notepad case to illustrate the use of gridbaglayout.

analysis:

Instructions with arrows can stretch.

4 occupies 4 squares and 6 occupies 4 squares. If setting 6 can stretch, then 4 will also stretch.

However, if 4 stretching is set, the column where 7 is located can also be stretched, so 4 cannot set stretching. We should set 4 to follow 6 for stretching.

The gray line is to see the general layout and the number of grids occupied by components.

Display effect at run time

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>