Weightx and Weighty in Java GridBagLayout

前端 未结 2 817
误落风尘
误落风尘 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:05

    If the space within a Panel is greater than the preferredDimension of the components contained within, the weightx and weighty is used to distribute the extra space to the individual components.

    use values from 0.0 to 1.0 (think of this a percentage).

    • weightx is horizontal spacing

    • weighty is vertical spacing

    The most common scenario in desktops is that the side panes stay a fixed size (weightx/weighty = 0.0) and the center pane takes up the remaining space (weightx/weighty = 1.0). however, using variations, you can have complete control of how your application resizes the individual components as the Frame size changes.

提交回复
热议问题