2
votes

I have created a form and added a container. I am trying to add a component to the container by using this code

    Component container = new Container(new GridBagLayout());        
    try{        
        GridBagConstraints c = new GridBagConstraints();
        c.fill = 2;
        c.weightx = 0.2d;
        c.gridx = 0;
        c.gridy = 0;
        container.addComponent((Object) c, new Label("My Label"));
        ....
    } catch (Exception e) 
    {
    }

However when use this code I get this error ...

cannot find symbol
symbol:   method addComponent(Object,Component)
location: variable container of type Component

I have followed all the instructions on the website but I cannot seem to add this component

Thanks

1

1 Answers

2
votes

No try but I think that

Component container = new Container(new GridBagLayout());        

should be replaced by :

Container container = new Container(new GridBagLayout());        

since addComponent() is not a method of Component but of Container. You can see that in the javadoc :

https://www.codenameone.com/javadoc/com/codename1/ui/Component.html

https://www.codenameone.com/javadoc/com/codename1/ui/Container.html