Java JButton Settings findButton(Container container, String text)

Here you can find the source of findButton(Container container, String text)

Description

Traverse a container hierarchy and returns the button with the given text

License

Open Source License

Declaration

static JButton findButton(Container container, String text) 

Method Source Code


//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;
    }
}

Related

  1. drawActiveButtonBorder(Graphics g, int x, int y, int w, int h)
  2. drawDefaultButtonBorder(Graphics g, int x, int y, int w, int h, boolean active)
  3. emphasizeButton(AbstractButton btn)
  4. equalizeButtonSizes(JPanel jPanelButtons)
  5. filterMnemonic(final String s, final AbstractButton b)
  6. findButtonComponents(Container container, String label)
  7. findDescendantButtonWithText(Container root, String desiredText)
  8. fixButtonUI(AbstractButton button)
  9. formatButtonFromAction(Action a)