Example usage for java.awt Container add

List of usage examples for java.awt Container add

Introduction

In this page you can find the example usage for java.awt Container add.

Prototype

public void add(Component comp, Object constraints, int index) 

Source Link

Document

Adds the specified component to this container with the specified constraints at the specified index.

Usage

From source file:Main.java

public static void replaceComponent(Container cont, Component comp1, Component comp2, String constraints) {
    int index = -1;
    int i = 0;/*from  www.  j  a v a 2  s. com*/
    for (Component comp : cont.getComponents()) {
        if (comp.equals(comp1)) {
            index = i;
            break;
        }
        ++i;
    }
    // cont.setIgnoreRepaint(true);
    cont.remove(comp1);
    cont.add(comp2, constraints, index);
    cont.validate();
    // cont.setIgnoreRepaint(false);
    cont.repaint();
}