List of usage examples for java.awt Container getComponent
public Component getComponent(int n)
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; }// w w w . j a v a 2s .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
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; }// w w w. j av a 2 s .c o m } } } final MouseEvent adapted = convertMouseEvent(e, component, point); SwingUtilities.invokeLater(new Runnable() { public void run() { component.dispatchEvent(adapted); } }); }
From source file:Main.java
/** * Forces an immediate repaint of a component and all of its children. * * @param component/*from ww w . j a v a2s .c om*/ */ public static void paintImmediately(Component component) { // Paint the component if (component instanceof JComponent) { JComponent jcomponent = (JComponent) component; jcomponent.paintImmediately(jcomponent.getBounds()); } // Recursively paint children if (component instanceof Container) { Container container = (Container) component; int numberOfChildren = container.getComponentCount(); for (int i = 0; i < numberOfChildren; i++) { Component child = container.getComponent(i); paintImmediately(child); } } }
From source file:Main.java
/** * Enable container.//from www. ja v a 2 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
public static void setAllOpaque(Container c, boolean opaque) { if (c instanceof JComponent) { ((JComponent) c).setOpaque(opaque); for (int i = 0; i < c.getComponentCount(); i++) { Component comp = c.getComponent(i); if (comp instanceof Container) setAllOpaque((Container) comp, opaque); }/*from www . j av a2 s . c o m*/ } }
From source file:Main.java
public static void disableBuffer(Component comp, ArrayList<JComponent> dbcomponents) { if ((comp instanceof JComponent) && comp.isDoubleBuffered()) { JComponent jcomponent = (JComponent) comp; dbcomponents.add(jcomponent);//ww w . ja va 2s . c o m jcomponent.setDoubleBuffered(false); } if (comp instanceof Container) { Container container = (Container) comp; int count = container.getComponentCount(); if (count > 0) { for (int i = 0; i < count; i++) { Component component = container.getComponent(i); disableBuffer(component, dbcomponents); } } } }
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 w w w . j a v a2s . c o 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; }
From source file:Main.java
/** * Returns first component placed in the specified container which is * instance of specified class type or null if none found. * * @param container// ww w.j ava 2 s.co m * container to look for component in * @param componentClass * component class * @param recursive * whether to check all subcontainers or not * @param <T> * component class type * @return first component placed in the specified container which is * instance of specified class type or null if none found */ public static <T extends Component> T getFirst(final Container container, final Class<T> componentClass, final boolean recursive) { for (int i = 0; i < container.getComponentCount(); i++) { final Component component = container.getComponent(i); if (componentClass.isInstance(component)) { return (T) component; } if (recursive) { if (component instanceof Container) { final T first = getFirst((Container) component, componentClass, recursive); if (first != null) { return first; } } } } return null; }
From source file:Main.java
/** * Returns map of container child components preferred sizes. * * @param container//from ww w . ja va2 s .c o m * container to process * @return map of container child components preferred sizes */ public static Map<Component, Dimension> getChildPreferredSizes(final Container container) { final int cc = container.getComponentCount(); final Map<Component, Dimension> cps = new HashMap<Component, Dimension>(cc); for (int i = 0; i < cc; i++) { final Component component = container.getComponent(i); cps.put(component, component.getPreferredSize()); } return cps; }
From source file:Main.java
protected static void fillAllDescendants(Container c, Class findClass, boolean deep, Collection results) { if (findClass.isInstance(c)) { results.add(c);/*from w w w . j a v a2 s . c o m*/ if (!deep) return; } for (int i = 0; i < c.getComponentCount(); i++) { Component comp = c.getComponent(i); if (comp instanceof Container) fillAllDescendants((Container) comp, findClass, deep, results); } }