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). If I just have “new Label(‘xyz’)” that works fine, but I need each panel to have their own ClickListener as well. 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.In your example, the return type of
new Label("Test").addClickListener(...is the ClickListener’s addClickListener return type, which is void.You can create the label, add the click listener and then add it: