Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reason for calling setEnabled(false) in JPanel

Tags:

java

swing

jpanel

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.

like image 755
GrayR Avatar asked Mar 16 '12 01:03

GrayR


1 Answers

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.

like image 51
Java42 Avatar answered Oct 06 '22 00:10

Java42