Here you can find the source of findTree(Container container)
static JTree findTree(Container container)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.awt.Component; import java.awt.Container; import javax.swing.JTree; public class Main { /**/*from w w w .j av a2 s .com*/ * Traverse a container hierarchy and returns the first JMenuBar * it finds. * */ static JTree findTree(Container container) { Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof JTree) { return (JTree) component; } else if (component instanceof Container) { JTree tree = findTree((Container) component); if (tree != null) { return tree; } } } return null; } }