简体   繁体   English

绑定组件<->容器(Enabled属性)

[英]Binding Component <-> Container (Enabled property)

I'm just trying to work out the best way to replicate a pretty useful feature of Windows' Forms.Panel in Java. 我只是试图找到最好的方法来用Java复制Windows的Forms.Panel一个非常有用的功能。 Basically, when you disable a Windows Forms.Panel , all child control's are set to disabled too. 基本上,当您禁用Windows Forms.Panel ,所有子控件也都设置为Disabled。 However, their enabled property is preserved such that, when the the Panel is enabled again, any child control that was disabled before the Panel was disabled, remains disabled. 但是, 保留其启用属性,以便在再次启用Panel时,在禁用面板之前被禁用的所有子控件都保持禁用状态。

I can add a property listener for a JPanel to be triggered when it's enabled property is changed and then cycle through all the JPanel 's components and set them to disabled, but this wont preserve the component's enabled properties. 我可以为JPanel添加一个属性侦听器,以更改其启用属性时触发的JPanel ,然后循环浏览所有JPanel的组件并将其设置为Disabled,但这不会保留组件的启用属性。

Any suggestions? 有什么建议么?

A more complex solution can be found in the Disabled Panel entry. 在“ 禁用面板”条目中可以找到更复杂的解决方案。 Internally it uses a collection as suggested by mlk to track the components that where enabled. 在内部,它使用mlk建议的集合来跟踪已启用的组件。 Even if you don't like the proposed solution you can still use the Swing Utils class to easily get all the components on the panel. 即使您不喜欢建议的解决方案,您仍然可以使用Swing Utils类轻松获取面板上的所有组件。

将禁用的组件存储在集合中,并在重新启用它们时检查此集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM