Java Swing-如何禁用JPanel? [英] Java Swing - How to disable a JPanel?
本文介绍了Java Swing-如何禁用JPanel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JPanel
上有几个JComponent
,并且我想在按开始"按钮时禁用所有这些组件.
I have several JComponent
s on a JPanel
and I want to disable all of those components when I press a Start button.
目前,我正在通过以下方式明确禁用所有组件
At present, I am disabling all of the components explicitly by
component1.setEnabled(false);
:
:
但是无论如何,我可以一次禁用所有组件吗?我试图禁用将这些组件添加到的JPanel
But Is there anyway by which I can disable all of the components at once? I tried to disable the JPanel
to which these components are added by
panel.setEnabled(false);
但是没有用.
推荐答案
The panel should have a getComponents()
method which can use in a loop to disable the sub-components without explicitly naming them.
这篇关于Java Swing-如何禁用JPanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文