Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Disable all components by getComponents  RSS feed

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like to disable all components on the JPanel by calling getComponents.
The following is my test program, but all components (e.g. JTextField) are not disabled.
Please help.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your TextForm object, considered as a JPanel, doesn't have any components which are JTextFields. It does have some JPanels as components, which in turn have JTextFields as components. So if you wanted to use this method you would have to use it recursively, going through the tree of components.

But why do something complicated like that? Wouldn't it be easier to just keep a reference to the list of JTextFields, and call their setEnabled() method directly when you need to?

Edit: I just looked at your code again, and I see you already have that reference. So just have TextForm provide a method which calls setEnabled(false) on each of the JTextFields in the array, and have the other class call that method.
 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Your TextForm object, considered as a JPanel, doesn't have any components which are JTextFields. It does have some JPanels as components, which in turn have JTextFields as components. So if you wanted to use this method you would have to use it recursively, going through the tree of components.

But why do something complicated like that? Wouldn't it be easier to just keep a reference to the list of JTextFields, and call their setEnabled() method directly when you need to?

Edit: I just looked at your code again, and I see you already have that reference. So just have TextForm provide a method which calls setEnabled(false) on each of the JTextFields in the array, and have the other class call that method.


How to use it recursively (going through the tree of components)?
I like to create a function of reusable code with "form" as its parameter so that is why it is complicated.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disabled Panel has static methods you can use to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!