I try it this way:
jPanel.setEnabled(false);
But it does not work.
Is there another option?
I try it this way:
jPanel.setEnabled(false);
But it does not work.
Is there another option?
You should basically obtain all the components and deactivate them, as shown below:
public void enableComponents(Container container, boolean enable) {
Component[] components = container.getComponents();
for (Component component : components) {
component.setEnabled(enable);
if (component instanceof Container) {
enableComponents((Container)component, enable);
}
}
}
In the example you can see the Container attribute that would be your JPanel since it extends from the first as seen in the documentation of Container in the AWT documentation .
The complete example can be found at StackOverflow in English .
You must block each of the panel elements, for example:
jTextFile1.setEnabled(false);
jTextFile2.setEnabled(false);
With your code what you do is "deactivate" the JPanel itself (which really does not do much).
If you want to deactivate the elements contained in the JPanel
, you will have to obtain the list of these elements and go through it, deactivating each element separately.
for (Component component : jPanel.getComponents()) {
component.setEnabled(false);
}