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

Java-解释gridbag权重以显示像素关系/公式/转换,java,swing,math,pixel,gridbaglayout,Java,Swing,Math,Pixel,Gridbaglayout,我一直在玩GridBagLayout,但我似乎无法计算出在约束中使用特定的权重将获得多少像素 例如,假设我有一个1000像素的contentPane,其中有三个JPanels,权重(比如,weight)为0.1、0.1、0.8 我的第一个假设是面板1和面板2各为100像素,面板3为800像素。原来不是 如何获得与权重相关的精确像素数 问同样的问题,但答案虽然有用,却不能回答问题 没关系,我想我找到了答案: 显然,问题在于向单元格中添加了额外的空间 When more than one colum

我一直在玩
GridBagLayout
,但我似乎无法计算出在约束中使用特定的
权重将获得多少像素

例如,假设我有一个1000像素的
contentPane
,其中有三个
JPanel
s,权重(比如,
weight
)为0.1、0.1、0.8

我的第一个假设是面板1和面板2各为100像素,面板3为800像素。原来不是

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


问同样的问题,但答案虽然有用,却不能回答问题

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

显然,问题在于向单元格中添加了额外的空间

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.