问题
I have a composite widget, which contain many widgets (inside HorizontalPanel). How to disable all widgets inside HorizontalPanel or inside this composite? I can't find setEnabled() method in Composite or panels
回答1:
The only way to do it is to recursively get all children of the panel and call setEnabled(false) on each widget, which extends FocusWidget
回答2:
I'm sure you've already figured it out, but if anyone else is curious, this will enable or disable all nested FocusWidgets:
private void enableAllChildren(boolean enable, Widget widget)
{
if (widget instanceof HasWidgets)
{
Iterator<Widget> iter = ((HasWidgets)widget).iterator();
while (iter.hasNext())
{
Widget nextWidget = iter.next();
enableAllChildren(enable, nextWidget);
if (nextWidget instanceof FocusWidget)
{
((FocusWidget)nextWidget).setEnabled(enable);
}
}
}
}
回答3:
getWidget() method of Composite class is protected, hence you cant access widgets inside composite from outside packages. Hence you can not get children widgets of Composite without subclassing Composite.
来源:https://stackoverflow.com/questions/9240775/how-to-disable-all-widgets-inside-panel-or-inside-composite