File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Subject: Disabling a JPanel and all it's components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Subject: Disabling a JPanel and all it Watch "Subject: Disabling a JPanel and all it New topic
Author

Subject: Disabling a JPanel and all it's components

peter m hayward
Ranch Hand

Joined: Sep 27, 2012
Posts: 35
I have read the past by Gregg Bolinger
Tuesday, October 09, 2001 05:16 Subject: Disabling a JPanel and all it's components

and used the code however i have three jtextAreas on the panel that still remain active any ideas as to why that is and how to disable them as well
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

You can retreive all the components from your panel with getComponents() (it returns all components as Component array). Iterate through array with a loop and disable each component.
JTextArea is a specific component in this case. Actually, when you have it on your panel, what you get is not the text area, but scroll pane (automatically added when you add text area). So what you should actually do is implement a recursive method, that can pick those components that are "deeper" (like the case here). Once you have them all (e.g. in a list), disable all of them.


The quieter you are, the more you are able to hear.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Tell us why you want to disable everything,
as there may be a better approach.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Welcome to the Ranch

I presume this is the old thread you mentioned. I haven’t read it. Did it discuss the enable() and disable() methods? You are not supposed to use them any more; use setEnabled(true) or setEnabled(false). It is worth going through the hierarchy of Swing components and finding how many have setEnabled() methods at all; I can’t remember where that method is declared.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Subject: Disabling a JPanel and all it's components