List of usage examples for java.awt Container getComponents
public Component[] getComponents()
From source file:Main.java
/** * Returns list of all sub-containers for this container. * * @param container//from w w w . j av a 2 s .c o m * container to process * @param containers * list to collect sub-containers into * @return list of all sub-containers */ public static List<Container> collectAllContainers(final Container container, final List<Container> containers) { containers.add(container); for (final Component component : container.getComponents()) { if (component instanceof Container) { collectAllContainers((Container) component, containers); } } return containers; }
From source file:Main.java
static Map<String, Component> getComponents(Container container) { Map<String, Component> listComponent = Collections.EMPTY_MAP; if (container.getComponentCount() > 0) { listComponent = new HashMap<>(); for (Component component : container.getComponents()) { if (component.getName() != null) { if (component instanceof JScrollPane) { listComponent.putAll(getComponents(((JScrollPane) component).getViewport())); } else { listComponent.put(component.getName(), component); }/* w w w.ja v a2 s . c o m*/ } } } return listComponent; }
From source file:Main.java
private static void getAllJComponents(Container container, Collection<JComponent> collection) { if (container instanceof JComponent) { JComponent c = (JComponent) container; collection.add(c);// www. jav a2s .c o m } Component[] children = container.getComponents(); if (children != null) { for (int i = 0; i < children.length; i++) { Component c = children[i]; if (c instanceof Container) { getAllJComponents((Container) c, collection); } } } }
From source file:core.Helpers.java
/** * Extracts all JLabel, JTFAdvanced and JTAAdvanced from a Component[] and * all of its sub containers./*from w ww .j a v a 2 s .c om*/ * * @param inputList * @return */ public static Component[] extractAll(Component[] inputList) { ArrayList<Component> retVal = new ArrayList(); for (int i = 0; i < inputList.length; i++) { if (compare(inputList[i], new JLabel()) || compare(inputList[i], new cso.JTFAdvanced()) || compare(inputList[i], new JTAAdvanced()) || compare(inputList[i], new JALabel())) { //Check if the type fitts the list above if right add it ro rreturn lisst retVal.add(inputList[i]); } else { try { Container c = (Container) inputList[i]; //Typecast to container (If it fails the try will discard it) Component[] inner = extractAll(c.getComponents()); //Recursive call for getting all components from container for (int k = 0; k < inner.length; k++) { retVal.add(inner[k]); //Add all componenets to return arraylsit } } catch (Exception e) { } } } //Convert arraylist to array of type Component Component[] retArr = new Component[retVal.size()]; for (int i = 0; i < retVal.size(); i++) { retArr[i] = retVal.get(i); } return retArr; //Be happy and love Java. #SomeMetaShitRightHere #NextLevelCoding "YOLO }
From source file:Main.java
/** * Returns first focusable component found in the container. * * @param container container to process * @return first focusable component found in the container *//* ww w. j ava 2 s .c o m*/ public static Component findFocusableComponent(final Container container) { final FocusTraversalPolicy focusTraversalPolicy = container.getFocusTraversalPolicy(); if (focusTraversalPolicy != null) { return focusTraversalPolicy.getFirstComponent(container); } else { for (final Component component : container.getComponents()) { if (component.isFocusable()) { return component; } if (component instanceof Container) { final Component focusable = findFocusableComponent((Container) component); if (focusable != null) { return focusable; } } } return null; } }
From source file:AWTUtilities.java
/** * Enables or disables all the components within the specified container. * //from w w w . j a v a 2 s .c o m * This is a rather hacky method - it doesn't work well if there are both * enabled and disabled components in the container. */ public static void setContainerEnabled(Container container, boolean enabled) { Component[] children = container.getComponents(); for (int i = 0; i < children.length; i++) { Component child = children[i]; child.setEnabled(enabled); if (child instanceof Container) setContainerEnabled((Container) child, enabled); } }
From source file:com.hartveld.commons.test.swing.AbstractSwingFrameTest.java
private static <T> T lookup(final Container container, final String name, final Class<T> clazz) { LOG.trace("Looking up component of type {} in container {} ...", clazz.getName(), container.getName()); for (final Component c : container.getComponents()) { if (clazz.isAssignableFrom(c.getClass())) { if (name == null || name.equals(c.getName())) { @SuppressWarnings("unchecked") final T target = (T) c; return target; }/* www . j a v a2 s.c om*/ } else if (c instanceof Container) { final T nested = lookup((Container) c, name, clazz); if (nested != null) { return nested; } } } return null; }
From source file:com.att.aro.ui.view.MainFrame.java
/** * set up test conducted title to the location of related session *///from w w w . j a v a 2 s . c o m public static void setLocationMap() { Container container = window.frmApplicationResourceOptimizer.getContentPane(); Component[] components = container.getComponents(); if (components != null && components.length > 0) { Component bpComponent = components[0]; try { BestPracticesTab bpTab = (BestPracticesTab) bpComponent; bpTab.setScrollLocationMap(); } catch (Exception e) { e.printStackTrace(); } } }
From source file:FormLayoutTester.java
public Dimension preferredLayoutSize(Container parent) { Component[] components = parent.getComponents(); left = 0;/*from w w w . ja va 2 s .co m*/ right = 0; height = 0; for (int i = 0; i < components.length; i += 2) { Component cleft = components[i]; Component cright = components[i + 1]; Dimension dleft = cleft.getPreferredSize(); Dimension dright = cright.getPreferredSize(); left = Math.max(left, dleft.width); right = Math.max(right, dright.width); height = height + Math.max(dleft.height, dright.height); } return new Dimension(left + GAP + right, height); }
From source file:FormLayoutTester.java
public void layoutContainer(Container parent) { preferredLayoutSize(parent); // Sets left, right Component[] components = parent.getComponents(); Insets insets = parent.getInsets(); int xcenter = insets.left + left; int y = insets.top; for (int i = 0; i < components.length; i += 2) { Component cleft = components[i]; Component cright = components[i + 1]; Dimension dleft = cleft.getPreferredSize(); Dimension dright = cright.getPreferredSize(); int height = Math.max(dleft.height, dright.height); cleft.setBounds(xcenter - dleft.width, y + (height - dleft.height) / 2, dleft.width, dleft.height); cright.setBounds(xcenter + GAP, y + (height - dright.height) / 2, dright.width, dright.height); y += height;/* w w w .j a v a2s . c o m*/ } }