Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4530310

call to Container.add(String, Component) leads to unexpected IAE

XMLWordPrintable

    • sparc
    • solaris_2.5

      Name: idR10193 Date: 11/21/2001


      Please see the sample below that shows how call to
      "Component add(String name, Component comp)" method of Container class
      leads to unexpected IllegalArgumenException.

      Sample code:
      ============add.java (Sample1)===============================
      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 =========================
      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

      ======================================================================

            art Artem Ananiev (Inactive)
            idergali Ilya Dergalin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: