SUGGESTED FIX
--- GridBagLayout.java Tue Jun 7 14:44:24 2005
*** 1129,1144 ****
xMaxArray[i] = px;
}
/* Cache the current slave's size. */
! if (sizeflag == PREFERREDSIZE)
d = comp.getPreferredSize();
! else
d = comp.getMinimumSize();
constraints.minWidth = d.width;
constraints.minHeight = d.height;
if (calculateBaseline(comp, constraints, d)) {
hasBaseline = true;
}
/* Zero width and height must mean that this is the last item (or
--- 1129,1152 ----
xMaxArray[i] = px;
}
/* Cache the current slave's size. */
! // SM (1):
! // depending on the sizeflag cache the preferredSize or minimumSize,
! // but store values in different members so (4) and (5) have access
! // to the cached preferred size
! if (sizeflag == PREFERREDSIZE) {
d = comp.getPreferredSize();
! constraints.prefWidth = d.width;
! constraints.prefHeight = d.height;
! } else {
d = comp.getMinimumSize();
constraints.minWidth = d.width;
constraints.minHeight = d.height;
+ }
+
if (calculateBaseline(comp, constraints, d)) {
hasBaseline = true;
}
/* Zero width and height must mean that this is the last item (or
*** 1319,1338 ****
}
break;
case GridBagConstraints.ABOVE_BASELINE:
case GridBagConstraints.ABOVE_BASELINE_LEADING:
case GridBagConstraints.ABOVE_BASELINE_TRAILING:
! pixels_diff = constraints.minHeight +
constraints.insets.top +
constraints.insets.bottom + constraints.ipady;
maxAscent[curY] = Math.max(maxAscent[curY],
pixels_diff);
break;
case GridBagConstraints.BELOW_BASELINE:
case GridBagConstraints.BELOW_BASELINE_LEADING:
case GridBagConstraints.BELOW_BASELINE_TRAILING:
! pixels_diff = constraints.minHeight +
constraints.insets.top +
constraints.insets.bottom + constraints.ipady;
maxDescent[curY] = Math.max(maxDescent[curY],
pixels_diff);
break;
--- 1327,1346 ----
}
break;
case GridBagConstraints.ABOVE_BASELINE:
case GridBagConstraints.ABOVE_BASELINE_LEADING:
case GridBagConstraints.ABOVE_BASELINE_TRAILING:
! pixels_diff = constraints.prefHeight +
constraints.insets.top +
constraints.insets.bottom + constraints.ipady;
maxAscent[curY] = Math.max(maxAscent[curY],
pixels_diff);
break;
case GridBagConstraints.BELOW_BASELINE:
case GridBagConstraints.BELOW_BASELINE_LEADING:
case GridBagConstraints.BELOW_BASELINE_TRAILING:
! pixels_diff = constraints.prefHeight +
constraints.insets.top +
constraints.insets.bottom + constraints.ipady;
maxDescent[curY] = Math.max(maxDescent[curY],
pixels_diff);
break;
*** 1408,1420 ****
* First, figure out how wide the current slave needs to be.
* Then, see if it will fit within the current minWidth values.
* If it will not fit, add the difference according to the
* weightX array.
*/
!
pixels_diff =
! constraints.minWidth + constraints.ipadx +
constraints.insets.left + constraints.insets.right;
for (k = constraints.tempX; k < px; k++)
pixels_diff -= r.minWidth[k];
if (pixels_diff > 0) {
--- 1416,1432 ----
* First, figure out how wide the current slave needs to be.
* Then, see if it will fit within the current minWidth values.
* If it will not fit, add the difference according to the
* weightX array.
*/
! // SM (2):
! // calculate pixels_diff depending on the sizeflag,
! // using 'constraints.prefWidth' or 'constraints.minWidth'
! // respectively, this is needed because of change (1)
! int sizeflagWidth = (sizeflag == PREFERREDSIZE) ? constraints.prefWidth : constraints.minWidth;
pixels_diff =
! sizeflagWidth + constraints.ipadx +
constraints.insets.left + constraints.insets.right;
for (k = constraints.tempX; k < px; k++)
pixels_diff -= r.minWidth[k];
if (pixels_diff > 0) {
*** 1469,1478 ****
--- 1481,1495 ----
* First, figure out how tall the current slave needs to be.
* Then, see if it will fit within the current minHeight values.
* If it will not fit, add the difference according to the
* weightY array.
*/
+ // SM (3):
+ // calculate pixels_diff depending on the sizeflag,
+ // using 'constraints.prefHeight' or 'constraints.minHeight'
+ // respectively, this is needed because of change (1)
+ int sizeflagHeight = (sizeflag == PREFERREDSIZE) ? constraints.prefHeight: constraints.minHeight;
pixels_diff = -1;
if (hasBaseline) {
switch(constraints.anchor) {
case GridBagConstraints.BASELINE:
*** 1500,1525 ****
break;
case GridBagConstraints.ABOVE_BASELINE:
case GridBagConstraints.ABOVE_BASELINE_LEADING:
case GridBagConstraints.ABOVE_BASELINE_TRAILING:
pixels_diff = constraints.insets.top +
! constraints.minHeight +
maxDescent[constraints.tempY];
break;
case GridBagConstraints.BELOW_BASELINE:
case GridBagConstraints.BELOW_BASELINE_LEADING:
case GridBagConstraints.BELOW_BASELINE_TRAILING:
pixels_diff = maxAscent[constraints.tempY] +
! constraints.minHeight +
constraints.insets.bottom +
constraints.ipady;
break;
}
}
if (pixels_diff == -1) {
pixels_diff =
! constraints.minHeight + constraints.ipady +
constraints.insets.top +
constraints.insets.bottom;
}
for (k = constraints.tempY; k < py; k++)
pixels_diff -= r.minHeight[k];
--- 1517,1542 ----
break;
case GridBagConstraints.ABOVE_BASELINE:
case GridBagConstraints.ABOVE_BASELINE_LEADING:
case GridBagConstraints.ABOVE_BASELINE_TRAILING:
pixels_diff = constraints.insets.top +
! sizeflagHeight +
maxDescent[constraints.tempY];
break;
case GridBagConstraints.BELOW_BASELINE:
case GridBagConstraints.BELOW_BASELINE_LEADING:
case GridBagConstraints.BELOW_BASELINE_TRAILING:
pixels_diff = maxAscent[constraints.tempY] +
! sizeflagHeight +
constraints.insets.bottom +
constraints.ipady;
break;
}
}
if (pixels_diff == -1) {
pixels_diff =
! sizeflagHeight + constraints.ipady +
constraints.insets.top +
constraints.insets.bottom;
}
for (k = constraints.tempY; k < py; k++)
pixels_diff -= r.minHeight[k];
*** 1626,1648 ****
r.width -= (constraints.insets.left + constraints.insets.right);
r.y += constraints.insets.top;
r.height -= (constraints.insets.top + constraints.insets.bottom);
diffx = 0;
if ((constraints.fill != GridBagConstraints.HORIZONTAL &&
! constraints.fill != GridBagConstraints.BOTH)
! && (r.width > (constraints.minWidth + constraints.ipadx))) {
! diffx = r.width - (constraints.minWidth + constraints.ipadx);
! r.width = constraints.minWidth + constraints.ipadx;
}
diffy = 0;
if ((constraints.fill != GridBagConstraints.VERTICAL &&
! constraints.fill != GridBagConstraints.BOTH)
! && (r.height > (constraints.minHeight + constraints.ipady))) {
! diffy = r.height - (constraints.minHeight + constraints.ipady);
! r.height = constraints.minHeight + constraints.ipady;
}
switch (constraints.anchor) {
case GridBagConstraints.BASELINE:
r.x += diffx/2;
--- 1643,1673 ----
r.width -= (constraints.insets.left + constraints.insets.right);
r.y += constraints.insets.top;
r.height -= (constraints.insets.top + constraints.insets.bottom);
diffx = 0;
+ // SM (4):
+ // if component isn't filled, give it its preferred width
+ // but not wider than the available width:
+ // - now possible because of change (1)
+ // - same result as original calculation for container which size is greated than its preferred size
if ((constraints.fill != GridBagConstraints.HORIZONTAL &&
! constraints.fill != GridBagConstraints.BOTH)) {
! diffx = r.width - Math.min(r.width, constraints.prefWidth + constraints.ipadx);
! r.width -= diffx;
}
diffy = 0;
+ // SM (5):
+ // if component isn't filled, give it its preferred height
+ // but not taller than the available height
+ // - now possible because of change (1)
+ // - same result as original calculation for container which size is greated than its preferred size
if ((constraints.fill != GridBagConstraints.VERTICAL &&
! constraints.fill != GridBagConstraints.BOTH)) {
! diffy = r.height - Math.min(r.height, constraints.prefHeight + constraints.ipady);
! r.height -= diffy;
}
switch (constraints.anchor) {
case GridBagConstraints.BASELINE:
r.x += diffx/2;
*** 1775,1786 ****
int maxY = cellY + cellHeight -
layoutInfo.maxDescent[cons.tempY + cons.tempHeight - 1] +
cons.descent;
r.height = maxY - r.y;
if (!cons.isVerticallyResizable()) {
! r.y = maxY - cons.minHeight;
! r.height = cons.minHeight;
}
}
else {
int baseline; // baseline, relative to cellY
int ascent = cons.ascent; // baseline for component
--- 1800,1811 ----
int maxY = cellY + cellHeight -
layoutInfo.maxDescent[cons.tempY + cons.tempHeight - 1] +
cons.descent;
r.height = maxY - r.y;
if (!cons.isVerticallyResizable()) {
! r.y = maxY - cons.prefHeight;
! r.height = cons.prefHeight;
}
}
else {
int baseline; // baseline, relative to cellY
int ascent = cons.ascent; // baseline for component
*** 1819,1852 ****
}
}
if (!fits) {
// Doesn't fit, use min size and original ascent
ascent = cons.ascent;
! r.width = cons.minWidth;
! r.height = cons.minHeight;
}
}
r.y = cellY + baseline - ascent;
if (cons.isVerticallyResizable()) {
switch(cons.baselineResizeBehavior) {
case CONSTANT_ASCENT:
! r.height = Math.max(cons.minHeight,cellY + cellHeight -
r.y - cons.insets.bottom);
break;
case CENTER_OFFSET:
{
int upper = r.y - cellY - cons.insets.top;
int lower = cellY + cellHeight - r.y -
! cons.minHeight - cons.insets.bottom;
int delta = Math.min(upper, lower);
delta += delta;
! if ((cons.minHeight + cons.centerPadding +
delta) / 2 + cons.centerOffset != baseline) {
// Off by 1
delta--;
}
! r.height = cons.minHeight + delta;
r.y = cellY + baseline -
(r.height + cons.centerPadding) / 2 -
cons.centerOffset;
}
break;
--- 1844,1877 ----
}
}
if (!fits) {
// Doesn't fit, use min size and original ascent
ascent = cons.ascent;
! r.width = cons.prefWidth;
! r.height = cons.prefHeight;
}
}
r.y = cellY + baseline - ascent;
if (cons.isVerticallyResizable()) {
switch(cons.baselineResizeBehavior) {
###@###.### 2005-06-16 09:24:12 GMT
|
EVALUATION
The bug is against GridBagLayout, passing this to awt.
timothy.prinzing@eng 1999-09-16
This is a problem of JTextField not properly setting Minimum and Preferred Size
richard.ray@eng 2000-07-28
This still appears to be a swing bug.
###@###.### 2001-08-27
With GridBagLayout if you do not specify a fill other than GridBagConstraints.NONE, the size of the component will be either the min or pref. For example, lets say you have a Component with a min of 10 and a pref of 100. If the parent Container, with a GridBagLayout, only has 20 pixels available, it will adjust the Component to a size of 10 (its pref, 100, is too big). The submitter of this bug is asking for GridBagLayout, if the min/pref doesn't exactly match, that the size by scaled between the min and pref regardless of the fill. As this is a fundamental change in GridBagLayout, I'm reassigning to awt to evaluate if they want to make this change.
###@###.### 2001-08-27
AWT certainly does not want to make this change in the Merlin timeframe. Downgrading the priority.
###@###.### 2001-09-05
Name: osR10079 Date: 04/11/2004
The problem is still reproducible with tiger b45.
I wonder why this is not RFE.
###@###.### 2004-04-12
======================================================================
a wrong and high-visible behaviour.
###@###.### 2005-05-14 10:43:41 GMT
We receieved the attached contribution from java.net user (svenmeier).
After applying the patch, it does look like if fixed the problem.
However, due to a conflict we had to get a new version from Sven.
This new version seems to fix both the BaseLine tests that Scott
added as well as the original bug. Andrei also provided
a regression test for it. The attachment named sven.txt is the
original version, the second one (GridBagLayout.java) is the final
one after several back and forths to fix various problems.
This problem is now fixed.
###@###.### 2005-06-15 18:09:12 GMT
|