Java JButton Settings getAbstractButton(Container owner, String text)

Here you can find the source of getAbstractButton(Container owner, String text)

Description

get Abstract Button

License

Open Source License

Declaration

private static AbstractButton getAbstractButton(Container owner, String text) 

Method Source Code


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

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

import java.util.ArrayList;

import java.util.List;
import javax.swing.AbstractButton;

import javax.swing.JComponent;

public class Main {
    private static AbstractButton getAbstractButton(Container owner, String text) {
        for (Component c : owner.getComponents()) {
            if (c instanceof AbstractButton && ((AbstractButton) c).getText() != null
                    && ((AbstractButton) c).getText().equals(text))
                return (AbstractButton) c;
            else if (c instanceof JComponent) {
                AbstractButton b = getAbstractButton((JComponent) c, text);
                if (b != null)
                    return b;
            }/*from  ww w .j av a2 s .co m*/
        }
        return null;
    }

    public static List<JComponent> getComponents(Container owner, Class<?> clazz) {
        return getComponents(owner, clazz, false);
    }

    public static List<JComponent> getComponents(Container owner, Class<?> clazz, boolean onlyVisible) {
        List<JComponent> list = new ArrayList<JComponent>();
        for (Component c : owner.getComponents()) {
            if (clazz.isInstance(c) && (!onlyVisible || c.isShowing()))
                list.add((JComponent) c);
            else if (c instanceof JComponent) {
                for (JComponent b : getComponents((JComponent) c, clazz, onlyVisible))
                    list.add(b);
            }
        }
        return list;
    }
}

Related

  1. findButton(Container container, String text)
  2. findButtonComponents(Container container, String label)
  3. findDescendantButtonWithText(Container root, String desiredText)
  4. fixButtonUI(AbstractButton button)
  5. formatButtonFromAction(Action a)
  6. getAllButtons(Component topComponent)
  7. getbtnButton(String iconpath, String rolloverIconpath, String pressIconpath)
  8. getButton(Container c, String text)
  9. getButton(Container container, String text)