code: public Panel addComponent(int index, Component component) {
          if(component == null) {
              throw new IllegalArgumentException("Cannot add null component");
          }
          synchronized(components) {
              if(components.contains(component)) {
                  return this;
              }
              if(component.getParent() != null) {
                  component.getParent().removeComponent(component);
              }
              if (index > components.size()) {
                  index = components.size();
              }
              else if (index < 0) {
                  index = 0;
              }
              components.add(index, component);
          }
          component.onAdded(this);
          invalidate();
          return this;
      }
docs: Adds a new child component to the panel. Where within the panel the child will be displayed is up to the layout
  manager assigned to this panel. If the component has already been added to another panel, it will first be
  removed from that panel before added to this one.
  @param component Child component to add to this panel
  @param index At what index to add the component among the existing components
  @return Itself