Codename One 添加组件到容器
Codename One add component to container
我已经创建了一个表单并添加了一个容器。
我正在尝试使用此代码向容器添加一个组件
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
的方法,而是 Container
的方法。
您可以在 javadoc 中看到:
https://www.codenameone.com/javadoc/com/codename1/ui/Component.html
https://www.codenameone.com/javadoc/com/codename1/ui/Container.html
我已经创建了一个表单并添加了一个容器。 我正在尝试使用此代码向容器添加一个组件
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
的方法,而是 Container
的方法。
您可以在 javadoc 中看到:
https://www.codenameone.com/javadoc/com/codename1/ui/Component.html
https://www.codenameone.com/javadoc/com/codename1/ui/Container.html