如何在Swing中递归禁用组件? [英] How do I recursively disable my components in Swing?
本文介绍了如何在Swing中递归禁用组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何递归禁用JPanel中的所有组件?
How do I recursively disable all of my components in a JPanel?
推荐答案
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.
这篇关于如何在Swing中递归禁用组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文