【问题标题】:Java - explain gridbag weight to display pixels relationship/formula/conversionJava - 解释网格重量以显示像素关系/公式/转换
【发布时间】:2011-07-25 18:20:17
【问题描述】:

我一直在玩GridBagLayout,但我似乎无法弄清楚在约束中使用特定的weighting 会得到多少像素。

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

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

我如何才能获得与加权相关的准确预期像素数?

This question 提出了同样的问题,但答案虽然有帮助,但并没有回答问题。 :- /

【问题讨论】:

    标签: java swing math pixel gridbaglayout


    【解决方案1】:

    没关系,我想我找到了答案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.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 2019-04-22
      • 2011-12-04
      • 2020-09-09
      • 1970-01-01
      • 2012-12-12
      相关资源
      最近更新 更多