List of usage examples for java.awt Container getComponentCount
public int getComponentCount()
From source file:Util.java
public static final int getComponentIndex(Component component) { if (component != null && component.getParent() != null) { Container c = component.getParent(); for (int i = 0; i < c.getComponentCount(); i++) { if (c.getComponent(i) == component) return i; }//from w w w .j a v a 2s. c o m } return -1; }
From source file:Main.java
@SuppressWarnings("unchecked") private static <T> void addAllOf(Container container, Class<T> clazz, List<T> all) { int count = container.getComponentCount(); if (container.getClass().equals(clazz)) { all.add((T) container);// ww w . j a v a2 s . com } for (int i = 0; i < count; i++) { Component component = container.getComponent(i); if (component instanceof Container) { addAllOf((Container) component, clazz, all); // Recursive } else if (component.getClass().equals(clazz)) { all.add((T) component); } } }
From source file:Main.java
/** * Enable container.// w ww. j ava2 s . c o m * * @param cont * the cont * @param enable * the enable */ public static void enableContainer(final Container cont, final boolean enable) { final int count = cont.getComponentCount(); Component comp; for (int i = 0; i < count; i++) { comp = cont.getComponent(i); if (comp instanceof JPanel || comp instanceof Box) { enableContainer((Container) comp, enable); } else { if (comp instanceof JTextField) { ((JTextField) comp).setEnabled(enable); } else if (!(comp instanceof JLabel)) { comp.setEnabled(enable); } } } }
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 .j a v a 2 s .c om } } } return listComponent; }
From source file:Main.java
public static void swingDispatch(MouseEvent e, Point point, final Component component) { synchronized (component.getTreeLock()) { if (component instanceof Container) { Container container = (Container) component; for (int i = container.getComponentCount(); i-- != 0;) { Component child = container.getComponent(i); Rectangle r = child.getBounds(); if (r.contains(point)) { swingDispatch(e, new Point(point.x - r.x, point.y - r.y), child); return; }/*ww w. j a va2 s . c om*/ } } } final MouseEvent adapted = convertMouseEvent(e, component, point); SwingUtilities.invokeLater(new Runnable() { public void run() { component.dispatchEvent(adapted); } }); }
From source file:Main.java
public static void addKeyAdapterRecursively(final Container container, final KeyAdapter keyAdapter) { container.addKeyListener(keyAdapter); for (int i = 0; i < container.getComponentCount(); i++) { final Component child = container.getComponent(i); if (child instanceof Container) { addKeyAdapterRecursively((Container) child, keyAdapter); }//from w w w . j a va2s.c o m child.addKeyListener(keyAdapter); } }
From source file:Main.java
public static Component getChild(Component parent, String name) { parent = getContainer(parent);// ww w . j a v a 2s . com if (parent instanceof JSplitPane) { JSplitPane split = (JSplitPane) parent; if (JSplitPane.TOP.equals(name)) { return split.getTopComponent(); } else if (JSplitPane.LEFT.equals(name)) { return split.getLeftComponent(); } else if (JSplitPane.RIGHT.equals(name)) { return split.getRightComponent(); } else if (JSplitPane.BOTTOM.equals(name)) { return split.getBottomComponent(); } } Container cont = (Container) parent; for (int i = 0; i < cont.getComponentCount(); i++) { Component comp = cont.getComponent(i); if (name.equals(comp.getName())) { return comp; } } if (name.endsWith(VIEW_SUFFIX)) { String subName = name.substring(0, name.length() - VIEW_SUFFIX.length()); if (subName.isEmpty()) { return parent; } return getContainer(getChild(parent, subName)); } throw new IllegalArgumentException("No component named " + name); }
From source file:Main.java
static public <T> void findDescentdantsOfType(List<T> holder, Container acomp, Class<T> type) { if (type.isInstance(acomp)) holder.add((T) acomp);//from w w w . j a va 2 s . c om for (int i = 0; i < acomp.getComponentCount(); i++) { Component child = acomp.getComponent(i); if (child instanceof Container) { findDescentdantsOfType(holder, (Container) child, type); } } }
From source file:Main.java
public static final Component getChildAtLine(Container container, Point p, boolean horizontal) { if (horizontal) { for (int i = 0; i < container.getComponentCount(); i++) { Component c = container.getComponent(i); if (p.x >= c.getX() && p.x < c.getX() + c.getWidth()) return c; }//from w ww.j a va 2 s . co m } else { for (int i = 0; i < container.getComponentCount(); i++) { Component c = container.getComponent(i); if (p.y >= c.getY() && p.y < c.getY() + c.getHeight()) return c; } } return null; }
From source file:Main.java
/**Devuelve el componente que tiene el actioncomand psComando*/ public static JComponent getComponente(Container poContenedor, String psAccion) { JComponent loResult = null;/*from www.j a v a 2 s .co m*/ for (int i = 0; i < poContenedor.getComponentCount() && loResult == null; i++) { Component loComp = poContenedor.getComponent(i); if (loResult == null && JButton.class.isAssignableFrom(loComp.getClass())) { if (((JButton) loComp).getActionCommand() != null && ((JButton) loComp).getActionCommand().equals(psAccion)) { loResult = ((JButton) loComp); } } if (loResult == null && JLabel.class.isAssignableFrom(loComp.getClass())) { if (((JLabel) loComp).getName() != null && ((JLabel) loComp).getName().equals(psAccion)) { loResult = ((JLabel) loComp); } } if (loResult == null && JComboBox.class.isAssignableFrom(loComp.getClass())) { if (((JComboBox) loComp).getName() != null && ((JComboBox) loComp).getName().equals(psAccion)) { loResult = ((JComboBox) loComp); } } if (loResult == null && JInternalFrame.class.isAssignableFrom(loComp.getClass())) { if (((JInternalFrame) loComp).getName() != null && ((JInternalFrame) loComp).getName().equals(psAccion)) { loResult = ((JInternalFrame) loComp); } } if (loResult == null && Container.class.isAssignableFrom(loComp.getClass())) { loResult = getComponente(((Container) loComp), psAccion); } // if(loComp.getClass().isAssignableFrom(JToolBar.class) ){ // loResult = getComponente(((JToolBar)loComp), psAccion); // } } return loResult; }