JDK-6299377 : REG: GridBagLayout does not layout properly if preferred size of some components are large
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris
  • CPU: generic,x86
  • Submitted: 2005-07-20
  • Updated: 2011-01-19
  • Resolved: 2005-10-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b55Fixed
Related Reports
Duplicate :  
Relates :  
Description
If some components in GridBagLayout have larger preferred size, other components in the panel are not shown. This is regression introduced in mustang b43. In earlier releases the component was resized appropriately so that all components are shown.

This regression is affecting many of the existing applications.
Attached is the screenshot and sample codes.
###@###.### 2005-07-20 15:05:35 GMT

Comments
EVALUATION We found that this regression breaks many user applications and there is also no way to fix this regression and keep 4238932 fixed. We decided to backout the fix for 4238932 for now and we will try to introduce new layouting policy for GridBagLayout via java property. (-Djava.awt.gridbaglayout.preferredsizepolicy = true ?)
23-09-2005

EVALUATION After the fix for 4238932 we obtained the behaviour that based on distribution algorithm that starts from PreferredSize of components in it. This is just in one case but this case is very important and many applications already use it. Before these changes we started distribution from MinimumSize but other applications worked wrong. We found that both approaches may not be merged together to achieve both goals described above. Most wise decision would be to introduce a new java property to switch two different scenarios and add a note into ReleaseNotes about that.
16-09-2005

EVALUATION When we doing ArrangeGrid() we choose the method of layouting (MINSIZE or PREFERREDSIZE) which would give sufficient place to store all components within particular container. For this purpose we assing variable "GridBagLayoutInfo info". Actually there is also another variable named layoutInfo which become near unusable after fix 4238932. But later in ArrangeGrid() and some other methods like (getLayoutDimensions(), etc) we do use "layoutInfo" instead of just "info". All this is concerned to the case when there is not enough space (so called MINSIZE case). All we need is to store actual data into layoutInfo when this case happen.
08-08-2005

SUGGESTED FIX *** src/share/classes/java/awt/GridBagLayout.java- *** 2050,2059 **** --- 2050,2061 ---- // if there is not enough space available in the parent, // store the layout info for minimum size in the local // variable 'info', leaving the reference to 'layoutInfo' // untouched info = getLayoutInfo(parent, MINSIZE); + layoutInfo = info; + d = getMinSize(parent, info); } else { // SM (8): // there is enough space available, so reuse the layout // info for preferred size (won't be used anyway) info = layoutInfo; *** (#1 of 1): [ UNSAVED ] ###@###.###
08-08-2005

EVALUATION During the fix 4238932 we handled the case when there is not enought space to store all components within the limits of container. There was a problem that if component's preferred size is larger then free space then LayoutManager forces it to collapse to minimum size. Seems the reasong in determining the case where we are able to give any component ability to spread itself to its PreferredSize: GridBagLayout.java: // 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; } This is not single spot.
04-08-2005

EVALUATION The regression is a consequence of fix for 4238932: a JTextField in gridBagLayout does not properly set MinimumSize. ###@###.### 2005-07-20 17:36:58 GMT
20-07-2005