diff --git a/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java b/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java index 2db5d704..cf071e41 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java +++ b/projects/samskivert/src/java/com/samskivert/swing/GroupLayout.java @@ -51,27 +51,26 @@ public abstract class GroupLayout /** * The weight of this component relative to the other components - * in the container. + * in the container. Only valid if the layout policy is STRETCH. */ public int weight = 1; /** - * Constructs a new constraints object with the specified - * fixedness and weight. - */ - public Constraints (boolean fixed) - { - this.fixed = fixed; - } - - /** - * Constructs a new constraints object with the specified - * fixedness and weight. + * Constructs a new constraints object with the specified weight, + * which is only applicable with the STRETCH policy. */ public Constraints (int weight) { this.weight = weight; } + + /** + * This constructor is not public, use the FIXED constant. + */ + protected Constraints (boolean fixed) + { + this.fixed = fixed; + } } /** A class used to make our policy constants type-safe. */ diff --git a/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java b/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java index 9c484dc4..76ac8df0 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java +++ b/projects/samskivert/src/java/com/samskivert/swing/HGroupLayout.java @@ -105,8 +105,8 @@ public class HGroupLayout extends GroupLayout if (_policy == STRETCH) { if (freecount > 0) { int freewid = b.width - info.fixwid - totgap; - defwid = freewid / freecount; - freefrac = freewid % freecount; + defwid = freewid / info.totweight; + freefrac = freewid % info.totweight; totwid = b.width; } else { totwid = info.fixwid + totgap; @@ -150,7 +150,11 @@ public class HGroupLayout extends GroupLayout if (_policy == NONE || isFixed(child)) { newwid = info.dimens[i].width; } else { - newwid = defwid + freefrac; + int wid = defwid; + if (_policy == STRETCH) { + wid *= getWeight(child); + } + newwid = wid + freefrac; // clear out the extra pixels the first time they're used freefrac = 0; } diff --git a/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java b/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java index 35bee6ae..f23c4431 100644 --- a/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java +++ b/projects/samskivert/src/java/com/samskivert/swing/VGroupLayout.java @@ -105,8 +105,8 @@ public class VGroupLayout extends GroupLayout if (_policy == STRETCH) { if (freecount > 0) { int freehei = b.height - info.fixhei - totgap; - defhei = freehei / freecount; - freefrac = freehei % freecount; + defhei = freehei / info.totweight; + freefrac = freehei % info.totweight; tothei = b.height; } else { tothei = info.fixhei + totgap; @@ -150,7 +150,11 @@ public class VGroupLayout extends GroupLayout if (_policy == NONE || isFixed(child)) { newhei = info.dimens[i].height; } else { - newhei = defhei + freefrac; + int hei = defhei; + if (_policy == STRETCH) { + hei *= getWeight(child); + } + newhei = hei + freefrac; // clear out the extra pixels the first time they're used freefrac = 0; }