How to disable all widgets inside Panel or inside Composite?

老子叫甜甜 提交于 2019-12-24 00:34:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!