Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Container; import java.util.Arrays; public class Main { /** * Adds all of the specified {@link Component components} with the given * constraints, then calls {@link #validate(Container)} on <tt>to</tt>. * * @param to * - the {@link Container} to add to * @param comps * - the components to add * @param constraints * - the constraints. If <tt>null</tt>, a new array of size * <tt>comps.length</tt> is created. * @see #validate(Container) */ public static void addAllAndValidate(Container to, Component[] comps, Object[] constraints) { if (constraints == null) { constraints = new Object[comps.length]; } else if (constraints.length < comps.length) { constraints = Arrays.copyOf(constraints, comps.length); } for (int i = 0; i < comps.length; i++) { to.add(comps[i], constraints[i]); } validate(to); } /** * Calls {@link Container#validate()} then {@link Container#repaint()} on * the given {@link Container} to fully reload the Container. * * @param c * - the Container to use * @see Container#repaint() * @see Container#validate() */ public static void validate(Container c) { c.validate(); c.repaint(); } }