List of usage examples for java.awt Container getComponents
public Component[] getComponents()
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
private Component findChildComponent(Container container, Class<? extends Object> cls) { final Component[] components = container.getComponents(); for (Component component : components) { if (cls.isInstance(component)) { return component; } else if (component instanceof Container) { Component c = findChildComponent((Container) component, cls); if (c != null) { return c; }/*from w w w . j a v a2 s . c o m*/ } } return null; }
From source file:de.innovationgate.utils.WGUtils.java
/** * Sets a swing/awt container and all of its child components enabled or * disabled/* w w w .j av a 2 s .c o m*/ * * @param con * The container * @param enabled * The state to set. true for enabled. false for disabled */ public static void setAllEnabled(Container con, boolean enabled) { Component[] children = con.getComponents(); for (int i = 0; i < children.length; i++) { children[i].setEnabled(enabled); } con.setEnabled(enabled); }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopWindow.java
protected java.awt.Component getComponentToFocus(java.awt.Container component) { if (component.isFocusable() && component.isEnabled() && DesktopComponentsHelper.isRecursivelyVisible(component)) { if (component instanceof JComboBox || component instanceof JCheckBox || component instanceof JTable || component instanceof JTree) { return component; } else if (component instanceof JTextComponent && ((JTextComponent) component).isEditable()) { return component; }//from w w w.j a va 2 s. co m } for (java.awt.Component child : component.getComponents()) { if (child instanceof JTabbedPane) { // #PL-3176 // we don't know about selected tab after request // may be focused component lays on not selected tab continue; } if (child instanceof java.awt.Container) { java.awt.Component result = getComponentToFocus((java.awt.Container) child); if (result != null) { return result; } } else { return child; } } return null; }
From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java
private void addHotKeyListener(final Container container) { final Component[] components = container.getComponents(); for (int i = 0; i < components.length; i++) { final Component component = components[i]; component.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(final java.awt.event.KeyEvent evt) { checkHotKey(evt);/*w w w .j av a2 s .c o m*/ } }); if (components[i] instanceof Container) { addHotKeyListener((Container) component); } } }
From source file:org.apache.cayenne.modeler.editor.SelectPropertiesPanel.java
public void setEnabled(boolean flag) { super.setEnabled(flag); // propagate to children Container mainPanel = (Container) getComponent(0); Component[] children = mainPanel.getComponents(); for (Component child : children) { child.setEnabled(flag);/*from ww w .j a v a 2s .co m*/ } }
From source file:org.datacleaner.widgets.DCFileChooser.java
private void setFilePaneBackground(Container container, Color bg) { Component[] children = container.getComponents(); for (Component component : children) { if (component instanceof JScrollPane) { // the "file pane" (the component containing the list of files) // is placed inside a JScrollPane JScrollPane scroll = (JScrollPane) component; setContainerBackground(scroll.getComponent(0), bg); } else if (component instanceof Container) { setFilePaneBackground((Container) component, bg); }/*w w w . ja v a 2s .c om*/ } }
From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java
/** * Returns all descendents of the given <code>component</code> * @param c a <code>component</code> value * @return a <code>collection</code> of the component's descendents or an * empty <code>collection</code> if nothing was found or <code>c</code> is null. *///from www . j ava2s. c om private Collection getComponents(Component c) { if (c instanceof Container) { Container cont = (Container) c; List list = new ArrayList(); list.addAll(Arrays.asList(cont.getComponents())); if (c instanceof JMenu) { list.add(((JMenu) c).getPopupMenu()); } else if (c instanceof Window) { list.addAll(Arrays.asList(((Window) c).getOwnedWindows())); } else if (c instanceof JDesktopPane) { // add iconified frames, which are otherwise unreachable // for consistency, they are still considerered children of // the desktop pane. int count = cont.getComponentCount(); for (int i = 0; i < count; i++) { Component child = cont.getComponent(i); if (child instanceof JInternalFrame.JDesktopIcon) { JInternalFrame frame = ((JInternalFrame.JDesktopIcon) child).getInternalFrame(); if (frame != null) { list.add(frame); } } } } return list; } // an empty ArrayList return new ArrayList(); }
From source file:org.eclipse.jubula.rc.swing.tester.adapter.JComboBoxAdapter.java
/** * Tries to find the component in the component hierarchy * @param component where to search/*from w ww .jav a 2 s. c om*/ * @param c type of the component which should be found * @return the desired component */ private Component getComponentViaHierarchy(Container component, Class c) { Component[] comps = component.getComponents(); for (int i = 0; i < comps.length; i++) { if (c.isInstance(comps[i])) { return comps[i]; } } for (int i = 0; i < comps.length; i++) { if (comps[i] instanceof Container) { Component ct = getComponentViaHierarchy((Container) comps[i], c); if (ct != null) { return ct; } } } return null; }
From source file:org.eclipse.wb.internal.swing.model.component.exposed.SwingHierarchyProvider.java
@Override public Object[] getChildrenObjects(Object object) throws Exception { // javax.swing.JMenu if (object instanceof JMenu) { JMenu menu = (JMenu) object; int componentCount = menu.getMenuComponentCount(); Component[] menuComponents = new Component[componentCount]; for (int i = 0; i < componentCount; i++) { menuComponents[i] = menu.getMenuComponent(i); }/*from ww w . j a v a 2s. co m*/ return menuComponents; } // generic java.awt.Container if (object instanceof Container) { Container container = (Container) object; return container.getComponents(); } // unknown return ArrayUtils.EMPTY_OBJECT_ARRAY; }
From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java
/** * Traverses through components hierarchy and prepares screen shot for every component passed in * <code>componentImages</code> map except for branch root if <code>isRoot</code> is * <code>true</code>.//from w w w . j a va 2 s.c o m * * @param component * the branch hierarchy root component. * @param componentImages * the {@link Map} of components which screen shots should be made for. This map would be * filled by prepared {@link java.awt.Image} instances. * @param rootComponent * this branch hierarchy root component. */ static void makeShotsHierarchy(Component component, Map<Component, java.awt.Image> componentImages, Component rootComponent) throws Exception { if (componentImages.containsKey(component) && component != rootComponent) { BufferedImage thisComponentImage = (BufferedImage) createComponentShotAWT(component); // BUG in OS X (Java 1.6.0_24-b07-334-10M3326): Component.printAll() returns no image // for AWT components and these components are not drawn on the JComponent container // using the same printAll() method. // The workaround is to hack into a native peer, get the native image and then paint it. if (EnvironmentUtils.IS_MAC && !(component instanceof JComponent)) { int width = Math.max(1, component.getWidth()); int height = Math.max(1, component.getHeight()); Image nativeImage = OSSupport.get().makeShotAwt(component, width, height); if (nativeImage != null) { BufferedImage rootImage = (BufferedImage) componentImages.get(rootComponent); Point rootLocation = rootComponent.getLocationOnScreen(); Point componentLocation = component.getLocationOnScreen(); thisComponentImage = ImageUtils.convertToAWT(nativeImage.getImageData()); rootImage.getGraphics().drawImage(thisComponentImage, componentLocation.x - rootLocation.x, componentLocation.y - rootLocation.y, null); } } componentImages.put(component, thisComponentImage); } if (component instanceof Container) { Container container = (Container) component; for (Component childComponent : container.getComponents()) { makeShotsHierarchy(childComponent, componentImages, rootComponent); } } }