Java-グリッドバッグの重量を説明して、ピクセルの関係/式/変換を表示する
-
25-10-2019 - |
質問
私は遊んでいます GridBagLayout
そして、私は特定のピクセルの数を理解できないようです weight
制約の中で。
たとえば、1000ピクセルがあるとします contentPane
3で JPanel
その中に、ウェイト付き(たとえば、 weighty
)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.
どうやら問題は、セルに追加のスペースが追加されることです。
所属していません StackOverflow