How to disable all components in a JPanel(如何禁用 JPanel 中的所有组件)
问题描述
在我的 JPanel 中,我有许多组件,包括其他 JPanel、JLabels、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?
注意:嵌套的 JPanel 中也有组件,就像顺序一样
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...
谢谢!感谢所有帮助!
推荐答案
查看 禁用面板有几个解决方案.
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 中的所有组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何禁用 JPanel 中的所有组件
基础教程推荐
- 将 double 转换为 Int,向下舍入 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
