Java JButton Settings lookupButton(Container c, String text)

Here you can find the source of lookupButton(Container c, String text)

Description

Find button by text

License

Open Source License

Parameter

Parameter Description
c a parameter
text a parameter

Declaration

private static JButton lookupButton(Container c, String text) 

Method Source Code


//package com.java2s;
//License from project: GNU General Public License 

import java.awt.Component;
import java.awt.Container;

import javax.swing.JButton;

public class Main {
    /**/*  w  w  w  .ja va 2  s.  com*/
     * Find button by text
     * 
     * @param c
     * @param text
     * @return
     */
    private static JButton lookupButton(Container c, String text) {
        JButton button = null;
        for (Component comp : c.getComponents()) {
            if (comp == null) {
                continue;
            }
            if (comp instanceof JButton && (button = (JButton) comp).getText() != null
                    && button.getText().equals(text)) {
                return button;
            } else if (comp instanceof Container) {
                if ((button = lookupButton((Container) comp, text)) != null) {
                    return button;
                }
            }
        }
        return button;
    }
}

Related

  1. interButtonSpace()
  2. isScrollBarButton(AbstractButton button)
  3. isSelected(AbstractButton... buttons)
  4. isSelected(final AbstractButton abstractButton)
  5. isSelected(final AbstractButton abstractButton)
  6. newTabbedPaneButton(String text)
  7. numberButtonGroup(ButtonGroup buttonGroup)
  8. opacityCheck(AbstractButton b)
  9. paintClassicText(AbstractButton b, Graphics g, int x, int y, String text, int mnemIndex)