I have JFrame with few JPanels on it. Each of JPanels has some components(JTextField, JCheckBox,...) or other JPanels on it, and so on...
I am trying to change property of one particular JCheckBox (namely, set it disabled) which is placed somewhere on form (on one of panels or one of it's child panels...).
I tried to play with reflection, but I didn't go far...
I made a method to iterate over all components, but I don't know how to compare component's name with checkbox name (chbAvailable).
When I try component.getName() I get null.
public static boolean getComponent(JComponent parent, String wantedComponentName){
try {
Component[] components = parent.getComponents();
for(int i = 0; i < components.length; i++){
if(components.getName().equals(wantedComponentName)){
components[i].setEnabled(false);
return true;
}
if(components[i] instanceof JPanel ||
components[i] instanceof JAPanel){
if(getComponent((JComponent)components[i], wantedComponentName)){
return true;
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return false;
}
Can someone please help me how can I (while iterating over components) get component name to compare it to checkbox name chbAvailable?