Here you can find the source of findMenuBar(Container container)
static JMenuBar findMenuBar(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.JMenuBar; public class Main { /**//from w w w . j a v a 2 s . co m * Traverse a container hierarchy and returns the first JMenuBar * it finds. * */ static JMenuBar findMenuBar(Container container) { Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof JMenuBar) { return (JMenuBar) component; } else if (component instanceof Container) { JMenuBar jmb = findMenuBar((Container) component); if (jmb != null) { return jmb; } } } return null; } }