Here you can find the source of getButton(Container c, String text)
static JButton getButton(Container c, String text)
//package com.java2s; //License from project: Open Source License import java.awt.*; import javax.swing.*; public class Main { static JButton getButton(Container c, String text) { if (c.isShowing()) { if (c.getComponents().length == 0) { if (c instanceof JButton) { JButton b = (JButton) c; String btxt = b.getText(); if (btxt != null && btxt.equalsIgnoreCase(text)) { return b; }/*w w w . j a va 2 s .c o m*/ } } else { for (Component sub : c.getComponents()) { if (sub instanceof Container) { JButton b = getButton((Container) sub, text); if (b != null) { return b; } } } } } return null; } }