Java JButton Settings getListenedButtonsFor(Container c)

Here you can find the source of getListenedButtonsFor(Container c)

Description

get Listened Buttons For

License

Open Source License

Declaration

public static List<JButton> getListenedButtonsFor(Container c) 

Method Source Code

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

import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;

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

public class Main {
    public static List<JButton> getListenedButtonsFor(Container c) {
        List<JButton> filter = null;
        List<JButton> result = new ArrayList<JButton>();
        searchFor(c, JButton.class, filter = new ArrayList<JButton>(), null);
        for (JButton button : filter) {
            if (button.getActionListeners().length > 0) {
                result.add(button);//from   www. j a va2s  . c  om
            }
        }
        return result;
    }

    private static void searchFor(Container c, Class cls, List list, String name) {
        if (!isEmpty(c.getComponents())) {
            for (Component comp : c.getComponents()) {
                if (cls.isInstance(comp)
                        && (name == null ? true : (comp.getName() != null && comp.getName().matches(name)))) {
                    list.add(comp);
                } else if (comp instanceof Container) {
                    searchFor((Container) comp, cls, list, name);
                }
            }
        }
    }

    public static boolean isEmpty(Object o) {
        return o == null || (o instanceof String && o.toString().trim().equals(""));
    }
}

Related

  1. getButtonSelectedInt(ButtonGroup buttonGroup)
  2. getButtonSelectedString(ButtonGroup buttonGroup)
  3. getDefaultFatButtonMargin()
  4. getHudControlShadowSize(AbstractButton button)
  5. getIcon(AbstractButton b)
  6. getMonospaceButton(final String text, final int size)
  7. getPreferredButtonSize(AbstractButton b, int textIconGap)
  8. getPreferredButtonSize(AbstractButton b, int textIconGap)
  9. getPressedButtonIcon(int x, int y)