Java Code Examples for javax.swing.JComponent#getComponents()

The following examples show how to use javax.swing.JComponent#getComponents() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
  * Returns a set of all components under the given parent.
  * @param parent the parent
  * @return the set of components
  */
 public static Set<JComponent> allComponents(JComponent parent) {
 	Set<JComponent> result = new HashSet<>();
 	Deque<JComponent> queue = new LinkedList<>();
 	queue.add(parent);
 	while (!queue.isEmpty()) {
 		JComponent c = queue.removeFirst();
 		result.add(c);
for (Component c0 : c.getComponents()) {
	if (c0 instanceof JComponent) {
		queue.add((JComponent)c0);
	}
}
 	}
 	result.remove(parent);
 	return result;
 }
 
Example 2
private static void checkVisibility(JComponent comp) {
    if (comp == null) return;

    comp.invalidate();
    comp.revalidate();
    comp.doLayout();
    comp.repaint();

    for (Component c : comp.getComponents())
        if (c.isVisible()) {
            comp.setVisible(true);

            return;
        }

    comp.setVisible(false);
}
 
Example 3
Source Project: netbeans   File: RunAnalysisPanel.java    License: Apache License 2.0 6 votes vote down vote up
void started() {
    started = true;
    
    ((CardLayout) progress.getLayout()).show(progress, "progress");
    progress.invalidate();

    //disable all elements in the dialog:
    List<JComponent> todo = new LinkedList<JComponent>();

    todo.add(this);

    while (!todo.isEmpty()) {
        JComponent c = todo.remove(0);

        if (c == progress) continue;

        c.setEnabled(false);

        for (Component child : c.getComponents()) {
            if (child instanceof JComponent) todo.add((JComponent) child);
        }
    }
}
 
Example 4
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 5
Source Project: pumpernickel   File: ControlGridLayout.java    License: MIT License 5 votes vote down vote up
@Override
public int getBaseline(JComponent c, int width, int height) {
	Map<Component, Rectangle> blueprint = ControlGridLayout.this
			.createBlueprint(c);

	for (Component child : c.getComponents()) {
		Rectangle r = blueprint.get(child);
		if (r != null) {
			int y = child.getBaseline(r.width, r.height);
			return y + r.y;
		}
	}

	return super.getBaseline(c, width, height);
}
 
Example 6
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 7
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 8
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 9
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 10
Source Project: pumpernickel   File: AnimatedLayout.java    License: MIT License 5 votes vote down vote up
@Override
protected void uninstall(JComponent parent) {
	super.uninstall(parent);
	ContainerListener l = (ContainerListener) parent
			.getClientProperty(PROPERTY_CONTAINER_LISTENER);
	parent.putClientProperty(PROPERTY_CONTAINER_LISTENER, null);
	parent.removeContainerListener(l);
	for (Component c : parent.getComponents()) {
		((JComponent) c).putClientProperty(
				"animatedLayout.propertyListener", null);
		((JComponent) c).removePropertyChangeListener(
				PROPERTY_DESTINATION, destinationListener);
	}
}
 
Example 11
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 12
Source Project: pumpernickel   File: AnimatingInspectorPanel.java    License: MIT License 5 votes vote down vote up
/**
 * Set double buffering for a component and all of its descendants.
 */
private static void setDoubleBuffered(JComponent jc, boolean b) {
	jc.setDoubleBuffered(b);
	for (Component c : jc.getComponents()) {
		if (c instanceof JComponent)
			setDoubleBuffered((JComponent) c, b);
	}
}
 
Example 13
Source Project: Bytecoder   File: ColorChooserPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 14
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 15
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 16
Source Project: Astrosoft   File: UIUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void setPanelBackground(JComponent panel, Color color) {
	if (panel!=null){
		panel.setBackground(color);
		for (Component c : panel.getComponents()) {
			if (c instanceof JPanel) {
				setPanelBackground((JPanel) c, color);
			}
		}
	}	
}
 
Example 17
/**
 * Convenient method to empty all the text fields of a given JComponent.
 *
 * @param component the component to "blank".
 */
public static void emptyFields (JComponent component)
{
    for (Component comp : component.getComponents()) {
        if (comp instanceof JTextField) {
            ((JTextComponent) comp).setText("");
        }
    }
}
 
Example 18
Source Project: Java8CN   File: ColorChooserPanel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Allows to show context popup for all components recursively.
 *
 * @param component  the root component of the tree
 * @param value      whether or not the popup menu is inherited
 */
private static void setInheritsPopupMenu(JComponent component, boolean value) {
    component.setInheritsPopupMenu(value);
    for (Object object : component.getComponents()) {
        if (object instanceof JComponent) {
            setInheritsPopupMenu((JComponent) object, value);
        }
    }
}
 
Example 19
/**
 * Prepares the component for drawing. This recursively disables the double-buffering as this would interfere with the
 * drawing.
 *
 * @param c
 *          the component that should be prepared.
 */
private void prepareComponent( final Component c ) {
  if ( c instanceof JComponent ) {
    final JComponent jc = (JComponent) c;
    jc.setDoubleBuffered( false );
    final Component[] childs = jc.getComponents();
    for ( int i = 0; i < childs.length; i++ ) {
      final Component child = childs[i];
      prepareComponent( child );
    }
  }
}
 
Example 20
Source Project: netbeans   File: MarginViewportUI.java    License: Apache License 2.0 4 votes vote down vote up
public void installUI(JComponent c) {
    super.installUI(c);

    //Fetch the "no properties" string - it's not going to change
    //for the life of the session
    //        noPropsString = NbBundle.getMessage(MarginViewportUI.class,
    //            "CTL_NoProperties"); //NOI18N
    //Set an appropriate font and color.  Only really relevant on OS-X to
    //keep the font consistent with other NB fonts
    Color fg = UIManager.getColor("controlShadow"); //NOI18N

    if (fg == null) {
        fg = Color.LIGHT_GRAY;
    }

    c.setForeground(fg);

    Color bg = UIManager.getColor("Tree.background"); //NOI18N

    if (bg == null) {
        bg = Color.WHITE;
    }

    c.setBackground(bg);

    Font f = UIManager.getFont("Tree.font"); //NOI18N

    if (f == null) {
        f = UIManager.getFont("controlFont"); //NOI18N
    }

    if (f != null) {
        c.setFont(f);
    }

    c.addContainerListener(this);

    Component[] kids = c.getComponents();

    for (int i = 0; i < kids.length; i++) {
        //Should almost always be empty anyway, if not only one component,
        //but for completeness...
        kids[i].addComponentListener(this);
    }
}