JDK-4529655 : invalid impl of GridBagLayout.addLayoutComponent(String, Component)
  • Type: Bug
  • Component: docs
  • Sub-Component: guides
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 2001-11-20
  • Updated: 2017-05-16
  • Resolved: 2003-11-14
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.
Other
5.0 b28Fixed
Related Reports
Relates :  
Description

Name: idR10193			Date: 11/20/2001

Spec for method "void addLayoutComponent(String name, Component comp)"
states: "Adds the specified component with the specified name to the
layout.". Actually component is not added after call to
addLayoutComponent(String, Component). Sample1 below demonstrates it.
One might think that you have to add component via call to methods of
Container but it is also impossible. None of methods of Container
that can take String as argument call this method of GridBagLayout,
see Sample2 and Sample3 below.

Sample code:
============addLC2.java (Sample1)===============================
import java.awt.*;

public class addLC2 {

    public static void main(String argv[]) {
        GridBagLayout gbl = new GridBagLayout();
        Container parent = new Container();
        parent.setLayout(gbl);

        Component comp = new Component(){};

        try {
            parent.add("component", comp);
        } catch (IllegalArgumentException iae) {
            System.out.println("IllegalArgumentException thrown from " +
                               "parent.add(\"component\", comp);");
        }

        try {
            parent.add(comp, "component");
        } catch (IllegalArgumentException iae) {
            System.out.println("IllegalArgumentException thrown from " +
                               "parent.add(comp, \"component\");");
        }

        System.out.println(gbl.minimumLayoutSize(parent));

        gbl.addLayoutComponent("component", comp);

        System.out.println(gbl.minimumLayoutSize(parent));
    }
}
============ end of addLC2.java =========================
Output under JDK version "1.4.0-rc-b86" ===================
~/bugs
javac addLC2.java
~/bugs
java addLC2
IllegalArgumentException thrown from parent.add("component", comp);
IllegalArgumentException thrown from parent.add(comp, "component");
java.awt.Dimension[width=0,height=0]
java.awt.Dimension[width=0,height=0]
~/bugs
==================================================

============add.java (Sample2)===============================
import java.awt.*;

public class add {

    public static void main(String argv[]) {
        GridBagLayout gbl = new GridBagLayout();
        Container parent = new Container();
        parent.setLayout(gbl);

        Component comp = new Component(){};

        parent.add("component", comp);
    }
}
============ end of add.java =========================
Output under JDK version "1.4.0-rc-b86" ===================
~/bugs
javac add.java
~/bugs
java add
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to
layout: constraints must be a GridBagConstraint
        at java.awt.GridBagLayout.addLayoutComponent(GridBagLayout.java:605)
        at java.awt.Container.addImpl(Container.java:485)
        at java.awt.Container.add(Container.java:313)
        at add.main(add.java:12)
~/bugs

============add.java (Sample3)===============================
import java.awt.*;

public class add2 {

    public static void main(String argv[]) {
        GridBagLayout gbl = new GridBagLayout();
        Container parent = new Container();
        parent.setLayout(gbl);

        Component comp = new Component(){};

        parent.add(comp, "component");
    }
}
============ end of add.java =========================
Output under JDK version "1.4.0-rc-b86" ===================
~/bugs
javac add2.java
~/bugs
java add2
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to
layout: constraints must be a GridBagConstraint
        at java.awt.GridBagLayout.addLayoutComponent(GridBagLayout.java:605)
        at java.awt.Container.addImpl(Container.java:485)
        at java.awt.Container.add(Container.java:348)
        at add2.main(add2.java:12)
~/bugs


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: tiger-beta INTEGRATED IN: tiger-b28 tiger-beta VERIFIED IN: tiger
14-06-2004

PUBLIC COMMENTS .
10-06-2004

EVALUATION The spec for GridBagLayout needs to be updated. GridBagLayout has never supported constraint objects other than GridBagConstraints. The docs for addLayoutComponent(String, Component) should document the IllegalArgumentException, and perhaps mention should be made in the GridBagLayout class docs as well. ###@###.### 2003-09-15 Actually the fix needs to be that Container.addImpl needs to have a comment that for GridBagLayout, the constraints object must be a GridBagConstraints, or an IAE will be thrown. The GridBagLayout.add(Component, String) method does document the IAE but, since it's called behind the scenes, it's not obvious to look there. Brent reviewed the fix. Approved by CCC. Fixed for tiger. ###@###.### 2003-10-13
13-10-2003