Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Subject: Disabling a JPanel and all it's components

 
peter m hayward
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell us why you want to disable everything,
as there may be a better approach.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49774
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic