如何禁用JPanel中的所有组件 [英] How to disable all components in a JPanel

查看:242
本文介绍了如何禁用JPanel中的所有组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JPanel中,我有很多组件,包括其他JPanel,JLabel,JTextAreas和JButton。因为我想实现一个教程模式,其中出现另一个窗口,我的主JPanel中的所有内容都被禁用,因为新窗口逐个解释每个'功能'...我想知道如何禁用我内部的所有组件原始JPanel。我知道你可以使用:

In my JPanel I have many components, including other JPanels, JLabels, JTextAreas, and JButtons. Becuase I want to implement a tutorial mode where another window appears and everything in my main JPanel is disabled as the new window explains each 'feature' one by one... I want a to know how to disable all the components that are inside my origiinal JPanel. I know you can use:

component.setEnabled(false);

但我不想为我的JPanel中的每个组件编写它。我想知道是否可以使用for循环或其他东西禁用JPanel中的所有组件?

But I don't want to write it for each component in my JPanel. I would like to know if it's possible to disable ALL components within my JPanel with a for loop or something?

注意:嵌套JPanels中也有组件,如命令将是

Note: There are also component in nested JPanels, like the order would be

主要JPanel --->嵌套JPanel --->组件

Main JPanel ---> Nested JPanel ---> Component

我也想要决赛组件也被禁用...

I also want the Final components to also be disabled...

谢谢!所有帮助表示赞赏!

Thanks! All help is appreciated!

推荐答案

查看已禁用面板,提供了几种解决方案。

Check out Disabled Panel for a couple of solutions.

一个使用禁用的GlassPane类型的方法,另一个使用递归方式禁用组件,同时跟踪组件的当前状态,以便以后可以正常启用。

One uses a disabled GlassPane type of approach and the other recursively disables components while keep track of the components current state so it can be enable properly later.

这篇关于如何禁用JPanel中的所有组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆