简体   繁体   English

将动态窗口小部件添加到面板(GWT)

[英]Adding dynamic widgets to a panel (GWT)

I'm having trouble adding a variable amount of labels to a panel. 我在向面板添加可变数量的标签时遇到问题。 My problem is that for some reason when adding my ClickListener it returns void instead of widget (error). 我的问题是,由于某种原因,当添加我的ClickListener它将返回void而不是小部件(错误)。 If I just have "new Label('xyz')" that works fine, but I need each panel to have their own ClickListener as well. 如果我只有“ new Label('xyz')”可以正常工作,但我还需要每个面板也有自己的ClickListener Here is the code: 这是代码:

for (int x = 0; x < productIDArray.length(); x++) {
  mainPanel.add(new Label("Test").addClickListener(new ClickListener() {
    @Override
    public void onClick(Widget sender) {
      // TODO Auto-generated method stub
    }
  }));
 }

The returned value from method chaining is always the last value. 方法链接返回的值始终是最后一个值。 If you change new A().b().c() , the returned type will be c's return type. 如果更改新的A().b().c() ,则返回的类型将为c的返回类型。

In your example, the return type of new Label("Test").addClickListener(... is the ClickListener's addClickListener return type, which is void. 在您的示例中, new Label("Test").addClickListener(... )的返回类型是ClickListener的addClickListener返回类型,它是无效的。

You can create the label, add the click listener and then add it: 您可以创建标签,添加点击监听器,然后添加它:

for(int x = 0;x<productIDArray.length();x++) {
  Label l = new Label("Test);
  l.addClickListener(...);
  mainPanel.add(l);
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM