How do I recursively disable my components in Swing?

 ̄綄美尐妖づ 提交于 2019-12-12 16:05:24

问题


How do I recursively disable all of my components in a JPanel?


回答1:


void setEnabled(Component component, boolean enabled) {
    component.setEnabled(enabled);
    if (component instanceof Container) {
        for (Component child : ((Container) component).getComponents()) {
            setEnabled(child, enabled);
        }
    }
}

Be aware that the previous enabled/disabled state of each component will be lost, unless you keep track of it somewhere else.



来源:https://stackoverflow.com/questions/13920279/how-do-i-recursively-disable-my-components-in-swing

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