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.