gpt4 book ai didi

Java - 解释gridbag权重显示像素关系/公式/转换

转载 作者:行者123 更新时间:2023-11-30 05:00:49 24 4
gpt4 key购买 nike

我一直在玩GridBagLayout,但我似乎无法弄清楚在特定的权重中我将获得多少像素限制条件。

例如,假设我有一个 1000 像素的 contentPane,其中包含三个 JPanel,权重(例如 weighty)为 0.1 , 0.1, 0.8。

我的第一个假设是面板 1 和 2 各为 100 像素,面板 3 为 800。事实证明并非如此。

如何获得与权重相关的确切像素数?

This question问了类似的问题,但答案虽然有帮助,但并没有回答问题。 :-/

最佳答案

没关系,我想我找到了答案here :

When more than one column has a non-zero weight, the excess space is 
distributed among the non-zero weight columns using the weight values.
In particular, if the excess space is P pixels, and the column weights
for column^i is weight^i, then column^i gets exactly
(weight^i * P) / (sum-of-all-column-weights). For example, if column 1
has weight 1 and column 2 has weight 2 and the excess space is 90 pixels,
column 1 will get 30 extra pixels and column 2 will get 60 extra pixels.
Rows with a non-zero weight behave in similar fashion.

显然问题是单元格中添加了额外的空间。

关于Java - 解释gridbag权重显示像素关系/公式/转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6810599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com