Java tutorial
//package com.java2s; import java.awt.Component; import javax.swing.JComponent; import javax.swing.text.JTextComponent; public class Main { /** * Sets opacity of a component and all of its children. * Excludes JTextComponent. */ public static void setOpaqueDeep(JComponent component, boolean opaque) { if (!(component instanceof JTextComponent)) { component.setOpaque(opaque); for (int i = 0; i < component.getComponentCount(); i++) { Component c = component.getComponent(i); if (c instanceof JComponent) { setOpaqueDeep((JComponent) c, opaque); } } } } }