0
votes

Is it possible to iterate a VerticalPanel and grab only certain widget.

I know you can do this with a list of string in GWT, but it doesnt work for widgets. I like the short hand iterration, however if there is a longer method, it is welcome as well.

Task: basically determine which checkbox in that panle is selected.

this works: basic foreach for(string i : my_list) ... ...

this wont: gwt widget for(checkbox ch : my_vpanel) ... ...

Error I get is: cannot convert from element type Widget to CheckBox

1

1 Answers

2
votes

You can iterate the widgets of a ComplexPanel such as

for (Widget widget : verticalPanel) {
    //Do stuff
}

or

Iterator<Widget> it = verticalPanel.iterator();
while(it.hasNext()){
    Widget widget = it.next();
    //Do stuff
}

or

for (int i=0;i<verticalPanel.getWidgetCount();i++){
    Widget widget = verticalPanel.getWidget(i);
    //Do stuff
}

and to see if a Widget is a type of CheckBox you can use

if (widget instanceof CheckBox){
    CheckBox checkBox = (CheckBox) widget;
}