在JPanel中调用setEnabled(false)的原因 [英] Reason for calling setEnabled(false) in JPanel

查看:486
本文介绍了在JPanel中调用setEnabled(false)的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Swing一段时间,但是在实际中从来没有遇到必须在JPanel中调用setEnabled(false)的情况. 尽管如此,我有时还是会在一些复杂的gui中看到这样的代码.但是我真的不理解为什么有人要使用它? 因此,在需要使用JPanel上的setEnabled(false)时,请给我一些现实生活中常见情况的示例.

I am working on Swing for a while now but never had a situation in practice when I had to call setEnabled(false) in JPanel. Still, I see such code sometimes in some sophisticated gui. But I really don't undarstand why someone wants to use it? So, please give me some examples of real life common situations when you need to use setEnabled(false) on JPanel.

也在javadoc中说:

Also in javadoc it says:

禁用组件不会禁用其子代.

Disabling a component does not disable its children.

实际上我有一个错误,因为在调整列大小时,禁用的JPanel中的表未显示鼠标调整大小的光标.我怀疑这里还有其他不愉快的惊喜.

actually I had a bug because table inside disabled JPanel didn't show mouse resize cursor when resizing columns. I suspect there are other unpleasant surprises here.

推荐答案

一个原因是getEnabled()将反映正确的状态. 考虑某些事件处理程序想要标记面板的情况 因为不再启用​​,因此在事件发生时并不谨慎 遍历并禁用所有子组件.其他部分 应用可能需要通过getEnabled()测试面板的状态,以 确定在应用程序的不同位置该怎么做.

One reason is so that getEnabled() will reflect the correct state. Consider a case where some event handler wants to flag the panel as no longer enabled and it is not prudent at the time of the event to iterate over and disable all child components. Other parts of the app might need to test the state of the panel via getEnabled() to determine what to do at different points in the app.

我个人从来不需要这样做,但是现在您问了我 以为我可能会用到这个.谢谢. && + = 1.

I personally never had to do this but now that you asked and got me thinking I might use this sometime. Thanks. &&+=1 to the question.

这篇关于在JPanel中调用setEnabled(false)的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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