Java tutorial
//package com.java2s; import java.awt.Component; import javax.swing.JComponent; public class Main { public static void printTree(JComponent c, int tabs) { if (c.getName() != null && !c.getName().contains("null") || tabs == 0) { for (int i = 0; i < tabs; i++) System.out.print(" "); System.out.println(c.getName() + " [" + c.getClass().getSimpleName() + "]"); } else tabs--; if (c.getComponents() == null) return; for (Component ci : c.getComponents()) { if (ci instanceof JComponent) printTree((JComponent) ci, tabs + 1); } } }