public static void replaceComponent(Component component, Component replacement) {

        if (!component.isAttached()) {
            throw new IllegalArgumentException("Component must be attached");
        }
        HasComponents parent = component.getParent();
        if (parent instanceof ComponentContainer) {
            ((ComponentContainer)parent).replaceComponent(component, replacement);
        } else if (parent instanceof SingleComponentContainer) {
            ((SingleComponentContainer)parent).setContent(replacement);
        } else {
            throw new IllegalArgumentException("Illegal class for parent: " + parent.getClass());
        }
    }
public static void replaceComponent ( Component component , Component replacement ) { if ( ! component . isAttached ( ) ) { throw new IllegalArgumentException ( "Component must be attached" ) ; } HasComponents parent = component . getParent ( ) ; if ( parent instanceof ComponentContainer ) { ( ( ComponentContainer ) parent ) . replaceComponent ( component , replacement ) ; } else if ( parent instanceof SingleComponentContainer ) { ( ( SingleComponentContainer ) parent ) . setContent ( replacement ) ; } else { throw new IllegalArgumentException ( "Illegal class for parent: " + parent . getClass ( ) ) ; } }
Replaces component with new component.<p>

@param component to be replaced
@param replacement new component