List of usage examples for java.awt Container getComponents
public Component[] getComponents()
From source file:Main.java
public static HashMap createComponentMap(Container ParentComponent) { // recursive add all sub-coponents into hashmap HashMap ComponentMap = new HashMap<String, Component>(); Component[] components = ParentComponent.getComponents(); for (Component comp : components) { if (comp instanceof Container) { ComponentMap.putAll(createComponentMap((Container) comp)); }/*from www . j a va2 s. c o m*/ for (int i = 0; i < components.length; i++) { ComponentMap.put(components[i].getName(), components[i]); } } return ComponentMap; }
From source file:Main.java
public static void replaceComponent(Container cont, Component comp1, Component comp2, String constraints) { int index = -1; int i = 0;//from ww w .jav a2 s . c o m for (Component comp : cont.getComponents()) { if (comp.equals(comp1)) { index = i; break; } ++i; } // cont.setIgnoreRepaint(true); cont.remove(comp1); cont.add(comp2, constraints, index); cont.validate(); // cont.setIgnoreRepaint(false); cont.repaint(); }
From source file:SpringDemo4.java
public static void setContainerSize(Container parent, int pad) { SpringLayout layout = (SpringLayout) parent.getLayout(); Component[] components = parent.getComponents(); Spring maxHeightSpring = Spring.constant(0); SpringLayout.Constraints pCons = layout.getConstraints(parent); //Set the container's right edge to the right edge //of its rightmost component + padding. Component rightmost = components[components.length - 1]; SpringLayout.Constraints rCons = layout.getConstraints(rightmost); pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(pad), rCons.getConstraint(SpringLayout.EAST))); //Set the container's bottom edge to the bottom edge //of its tallest component + padding. for (int i = 0; i < components.length; i++) { SpringLayout.Constraints cons = layout.getConstraints(components[i]); maxHeightSpring = Spring.max(maxHeightSpring, cons.getConstraint(SpringLayout.SOUTH)); }/*w w w .ja v a 2s .c o m*/ pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(pad), maxHeightSpring)); }
From source file:Main.java
/** * Disables component and all of its children recursively. * * @param component component to disable * @param startFromChilds whether should disable only component childs or not * @param excludePanels whether should exclude panels from disabling or not * @param excluded components to exclude from disabling * @param disabled list of actually disabled components *///from w w w. j a v a 2s .c om private static void disableRecursively(final Component component, final boolean startFromChilds, final boolean excludePanels, final List<Component> excluded, final List<Component> disabled) { final boolean b = !startFromChilds && !excluded.contains(component) && !(component instanceof JPanel && excludePanels); if (b && component.isEnabled()) { component.setEnabled(false); disabled.add(component); } if (component instanceof Container) { if (b && isHandlesEnableState(component)) { return; } final Container container = (Container) component; for (final Component child : container.getComponents()) { disableRecursively(child, false, excludePanels, excluded, disabled); } } }
From source file:Main.java
/** * The internal, recursive implementation of getChildComponents(Container, Class...). * * @param parent Container which's children are being gathered. * @param filter The class filter applied, may be null. * @param resultList The list of gathered child components. *///from ww w. j a va 2 s . c o m protected static void getChildComponents(final Container parent, final Class[] filter, final Collection resultList) { final Component[] components = parent.getComponents(); for (Component c : components) { if (filter.length == 0) resultList.add(c); else { for (Class f : filter) { if (f.isAssignableFrom(c.getClass())) { resultList.add(c); break; } } } if (c instanceof Container) getChildComponents((Container) c, filter, resultList); } }
From source file:Main.java
public final static Component getDescendantOfClass(Class<?> c, Container comp, boolean exactInstance) { Component theObject = null;/*from w ww . j a va2s . c o m*/ if (c != null && comp != null) { Component[] carray = comp.getComponents(); if (carray != null) { for (int i = 0; i < carray.length && theObject == null; i++) { if (exactInstance && carray[i].getClass() == c) { theObject = carray[i]; } else if (!exactInstance && c.isInstance(carray[i])) { theObject = carray[i]; } else if (carray[i] instanceof Container) { theObject = getDescendantOfClass(c, (Container) carray[i], exactInstance); } } } } return theObject; }
From source file:Main.java
public static void setFont(Container container, Font font) { container.setFont(font);/* w w w .j a v a2s. c om*/ trySetBorderFont(font, container); Component[] components = container.getComponents(); for (Component component : components) { component.setFont(font); if (component instanceof Container) { setFont((Container) component, font); } trySetBorderFont(font, component); if (component instanceof JTable) { JTable table = (JTable) component; table.getTableHeader().setFont(font); } } if (container instanceof JMenu) { JMenu jMenu = (JMenu) container; for (int i = 0; i < jMenu.getItemCount(); i++) { JMenuItem mi = jMenu.getItem(i); mi.setFont(font); } } }
From source file:Main.java
/** * Groups all buttons inside this container and all subcontainers if * requested and returns created button group. * * @param container/* w ww . java 2s .c om*/ * container to process * @param recursive * whether to check all subcontainers or not * @param buttonGroup * button group */ public static void groupButtons(final Container container, final boolean recursive, final ButtonGroup buttonGroup) { for (final Component component : container.getComponents()) { if (component instanceof AbstractButton) { buttonGroup.add((AbstractButton) component); } if (recursive) { if (component instanceof Container) { groupButtons(container, true); } } } }
From source file:Main.java
private static void doSetIgnoreRepaintInEDT(final Component component, final boolean ignoreRepaint) { component.setIgnoreRepaint(ignoreRepaint); if (component instanceof Container) { Container container = Container.class.cast(component); Component[] components = null; synchronized (container.getTreeLock()) { components = container.getComponents(); }/*from w w w .ja va 2 s . c om*/ for (int i = 0; i < components.length; i++) { doSetIgnoreRepaintInEDT(components[i], ignoreRepaint); } } }
From source file:Main.java
public static <T> T findChildByName(Container container, Class<T> returnType, String name) { if (name.equals(container.getName())) { return returnType.cast(container); }/*from ww w . j a v a2 s .c o m*/ for (Component component : container.getComponents()) { if (name.equals(component.getName())) { return returnType.cast(component); } else if (component instanceof Container) { T recursiveResult = findChildByName((Container) component, returnType, name); if (recursiveResult != null) { return returnType.cast(recursiveResult); } } } throw new IllegalArgumentException( "Did not find child component by name [" + name + "] in the specified container!"); }