Java - 解释gridbag权重显示像素关系/公式/转换
我一直在使用 GridBagLayout ,但我似乎无法弄清楚在约束中使用特定的权重会获得多少像素。
例如,假设我有一个 1000 像素的 contentPane
,其中包含三个 JPanel
,权重(例如 weighty
)为 0.1、0.1, 0.8。
我的第一个假设是面板 1 和 2 各为 100 像素,面板 3 为 800。事实证明并非如此。
如何获得与权重相关的确切像素数?
这个问题提出了同样的问题,但答案虽然有帮助,但并没有回答问题。 :- /
I've been playing around with GridBagLayout
and I can't seem to figure out how many pixels I'm going to get with a particular weight
ing in the constraints.
For example, say I have a 1000 pixel contentPane
with three JPanel
s in it, with weights (say, weighty
) of 0.1, 0.1, 0.8.
My first hypothesis was that panel 1 and 2 would be 100 pixels each, and panel 3 would be 800. Turns out it wasn't.
How can I get an exact number of pixels to expect with respect to the weighting?
This question asks sort of the same thing, but the answers, while helpful, don't answer the question. :- /
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系,我想我找到了答案这里:
显然问题是额外的空间被添加到单元格中。
Never mind, I think I found the answer here:
Apparently the problem is extra space being added to the cells.