Here you can find the source of findButton(Container container, String text)
static JButton findButton(Container container, String text)
//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.JButton; public class Main { /**//from w ww .j a v a 2s .co m * Traverse a container hierarchy and returns the button with * the given text * */ static JButton findButton(Container container, String text) { Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof JButton) { JButton button = (JButton) component; if (button.getText().equals(text)) { return button; } } else if (component instanceof Container) { JButton button = findButton((Container) component, text); if (button != null) { return button; } } } return null; } }