sdasdadas
sdasdadas

Reputation: 25096

How do I recursively disable my components in Swing?

How do I recursively disable all of my components in a JPanel?

Upvotes: 3

Views: 1500

Answers (1)

VGR
VGR

Reputation: 44308

void setEnabled(Component component, boolean enabled) {
    component.setEnabled(enabled);
    if (component instanceof Container) {
        for (Component child : ((Container) component).getComponents()) {
            setEnabled(child, enabled);
        }
    }
}

Be aware that the previous enabled/disabled state of each component will be lost, unless you keep track of it somewhere else.

Upvotes: 7

Related Questions