Java 代码名一个添加组件到容器
我已经创建了一个表单并添加了一个容器。 我试图使用以下代码向容器中添加一个组件Java 代码名一个添加组件到容器,java,codenameone,Java,Codenameone,我已经创建了一个表单并添加了一个容器。 我试图使用以下代码向容器中添加一个组件 Component container = new Container(new GridBagLayout()); try{ GridBagConstraints c = new GridBagConstraints(); c.fill = 2; c.weightx = 0.2d; c.gridx = 0;
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)
{
}
然而,当使用此代码时,我得到了这个错误
cannot find symbol
symbol: method addComponent(Object,Component)
location: variable container of type Component
我已经遵循了网站上的所有说明,但我似乎无法添加此组件
谢谢不用尝试,但我认为
Component container = new Container(new GridBagLayout());
应替换为:
Container container = new Container(new GridBagLayout());
因为addComponent()
不是Component
的方法,而是容器的方法。
您可以在javadoc中看到:
你能把链接贴到网站上吗?网站:哦,当然可以-多啦!成功了。非常感谢。太明显了。