Weightx and Weighty in Java GridBagLayout

前端 未结 2 822
误落风尘
误落风尘 2020-12-28 15:32

I have some trouble understanding these two properties. How should I give weight to components? How are these numbers calculated? I have tried to read several articles on th

2条回答
  •  太阳男子
    2020-12-28 16:23

    weightx and weighty are used to determine how to distribute space among columns and among rows.

    This values are important for specifying resizing behavior.If you do not specify any of weightx or weighty, all the components will clump together in the center of their container. See the doc of GridBagLayout for more information.

    For each column, the weight is related to the highest weightx specified for a component within that column. Similarly, each row's weight is related to the highest weighty specified for a component within that row.

提交回复
热议问题