United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4529655 invalid impl of GridBagLayout.addLayoutComponent(String, Component)
JDK-4529655 : invalid impl of GridBagLayout.addLayoutComponent(String, Component)

Details
Type:
Bug
Submit Date:
2001-11-20
Status:
Closed
Updated Date:
2004-03-20
Project Name:
JDK
Resolved Date:
2003-11-14
Component:
docs
OS:
solaris_2.5
Sub-Component:
guides
CPU:
sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
5.0 (b28)

Related Reports
Relates:

Sub Tasks

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
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
                                     
2003-10-13
PUBLIC COMMENTS

.
                                     
2004-06-10
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
generic

FIXED IN:
tiger-beta

INTEGRATED IN:
tiger-b28
tiger-beta

VERIFIED IN:
tiger


                                     
2004-06-14



Hardware and Software, Engineered to Work Together