How to disable all components in a JPanel

Check out Disabled Panel for a couple of solutions.

One uses a disabled GlassPane type of approach and the other recursively disables components while keep track of the components current state so it can be enable properly later.


Easy fast way :)

for (Component cp : yourPanle.getComponents() ){
        cp.setEnabled(false);
 }

I used the following function:

void setPanelEnabled(JPanel panel, Boolean isEnabled) {
    panel.setEnabled(isEnabled);

    Component[] components = panel.getComponents();

    for (Component component : components) {
        if (component instanceof JPanel) {
            setPanelEnabled((JPanel) component, isEnabled);
        }
        component.setEnabled(isEnabled);
    }
}