Java JButton Settings getButton(Container container, String text)

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

Description

get Button

License

Open Source License

Declaration

public static JButton getButton(Container container, String text) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static JButton getButton(Container container, String text) {
        JButton btn = null;/* w w w  . j  a va 2 s  . co m*/
        List<Container> children = new ArrayList<>(25);
        for (Component child : container.getComponents()) {
            if (child instanceof JButton) {
                JButton button = (JButton) child;
                if (text.equals(button.getText())) {
                    btn = button;
                    break;
                }
            } else if (child instanceof Container) {
                children.add((Container) child);
            }
        }
        if (btn == null) {
            for (Container cont : children) {
                JButton button = getButton(cont, text);
                if (button != null) {
                    btn = button;
                    break;
                }
            }
        }
        return btn;
    }
}

Related

  1. formatButtonFromAction(Action a)
  2. getAbstractButton(Container owner, String text)
  3. getAllButtons(Component topComponent)
  4. getbtnButton(String iconpath, String rolloverIconpath, String pressIconpath)
  5. getButton(Container c, String text)
  6. getButton(String displayText, ActionListener actionListener)
  7. getButtonAsLink(String text)
  8. getButtonBorderColor(Color color)
  9. getButtonColor()