Java GridBagLayout中的Weightx和Weighty [英] Weightx and Weighty in Java GridBagLayout
问题描述
我在理解这两个属性时遇到了一些麻烦。我该如何给予组件重量?这些数字是如何计算的?我曾试图在网上阅读几篇文章,但我不明白。
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 the web but I do not understand it.
谢谢。
推荐答案
如果Panel中的空间大于其中包含的组件的preferredDimension,则使用weightx和weighty将额外空间分配给各个组件。
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.
使用0.0到1.0之间的值(想想这个百分比)。
use values from 0.0 to 1.0 (think of this a percentage).
-
weightx是水平的间距
weightx is horizontal spacing
重量是垂直间距
桌面中最常见的情况是侧窗格保持固定大小(weightx / weighty = 0.0),中间窗格占用剩余空间(weightx / weighty = 1.0)。但是,使用变体,您可以完全控制应用程序在帧大小更改时如何调整单个组件的大小。
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.
这篇关于Java GridBagLayout中的Weightx和Weighty的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!