List of usage examples for java.awt Container getComponents
public Component[] getComponents()
From source file:Utils.java
public static List<Component> getAllComponents(final Container c) { Component[] comps = c.getComponents(); List<Component> compList = new ArrayList<Component>(); for (Component comp : comps) { compList.add(comp);/*from w ww .j ava 2s . com*/ if (comp instanceof Container) { compList.addAll(getAllComponents((Container) comp)); } } return compList; }
From source file:Main.java
public static Component find(Container parent, String name) { Component[] kids = parent.getComponents(); for (int x = 0; x < kids.length; x++) { if (name.equals(kids[x].getName())) { return kids[x]; } else if (kids[x] instanceof Container) { Component c = find((Container) kids[x], name); if (c != null) { return c; }// w w w.j a v a 2s. c o m } } return null; }
From source file:Main.java
public static void setComponentsFont(Container container, Font font) { Component[] components = container.getComponents(); container.setFont(font);/*from www.j a v a 2 s. co m*/ for (Component component : components) { component.setFont(font); if (component instanceof JMenu) { setComponentsFont((Container) component, font); } } }
From source file:Main.java
public static Component getFirstChildComponent(Container container, Class ofType) { java.awt.Component[] comps = container.getComponents(); Component comp = null;/*from w ww. ja v a 2 s.com*/ for (int n = 0; n < comps.length; n++) { System.out.println("WHat component am I " + n + ":" + comps[n] + " IN " + container); if (ofType.isInstance(comps[n])) return comps[n]; if (comps[n] instanceof JComponent || comps[n] instanceof Container) comp = getFirstChildComponent((Container) comps[n], ofType); if (comp != null) { // Does this component have the focus? boolean hasFocus = comp.hasFocus(); if (hasFocus) return comp; } } return null; }
From source file:Main.java
public static boolean hasOrContainsFocus(Component c) { if (c.hasFocus()) { return true; }/*from ww w . j av a 2 s . c o m*/ if (c instanceof Container) { Container container = (Container) c; for (Component childComponent : container.getComponents()) { if (hasOrContainsFocus(childComponent)) { return true; } } } return false; }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> List<T> getAllComponents(final Container c, Class<T> classType) { Component[] comps = c.getComponents(); List<T> compList = new ArrayList<T>(); for (Component comp : comps) { if (classType.isInstance(comp)) { compList.add((T) comp);//from www . ja v a2s. c o m } if (comp instanceof Container) { compList.addAll(getAllComponents((Container) comp, classType)); } } return compList; }
From source file:Main.java
public static List<Component> findChildComponentsOfType(Component component, Class<?> type) { List<Component> foundComponents = new ArrayList<Component>(); if (component instanceof Container) { Container container = (Container) component; for (Component child : container.getComponents()) { if (type.isAssignableFrom(child.getClass())) { foundComponents.add(child); }/* w ww.ja va 2 s . com*/ foundComponents.addAll(findChildComponentsOfType(child, type));// recursive } } return foundComponents; }
From source file:Main.java
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; }// w w w . j a v a 2 s. c o m } return null; }
From source file:Main.java
public static boolean findComponent(Container container, Component component) { for (Component comp : container.getComponents()) { if (comp == component) { return true; } else if (comp instanceof Container) { Container inner = (Container) comp; if (findComponent(inner, component)) { return true; }/* ww w . jav a 2s . co m*/ } } return false; }
From source file:Main.java
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);/* w w w . j a va 2 s. c o m*/ } else if (comp instanceof Container) { searchFor((Container) comp, cls, list, name); } } } }