java setenabled,在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.

Also in javadoc it says:

Disabling a component does not disable its children.

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.

解决方案

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.

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值