public void setLayoutDelegate(LayoutSupportDelegate newDelegate /*,
     boolean fromCode*/) throws Exception {
    LayoutConstraints<?>[] oldConstraints;
    LayoutSupportDelegate oldDelegate = layoutDelegate;

    if (layoutDelegate != null && (layoutDelegate != newDelegate /* || !fromCode*/)) {
      oldConstraints = removeLayoutDelegate(true);
    } else {
      oldConstraints = null;
    }

    layoutDelegate = newDelegate;
    propertySets = null;
    needInit = false;

    if (layoutDelegate != null) {
      try {
        layoutDelegate.initialize(this, null);
        fillLayout(oldConstraints);
        getPropertySets(); // force properties and listeners creation
      } catch (Exception ex) {
        removeLayoutDelegate(false);
        layoutDelegate = oldDelegate;
        if (layoutDelegate != null) {
          fillLayout(null);
        }
        throw ex;
      }
    }
  }
 public void initializeLayoutDelegate() throws Exception {
   if (layoutDelegate != null && needInit) {
     LayoutManager lmInstance =
         initializeFromInstance ? getPrimaryContainerDelegate().getLayout() : null;
     layoutDelegate.initialize(this, lmInstance); // , initializeFromCode);
     fillLayout(null);
     getPropertySets(); // force properties and listeners creation
     needInit = false;
   }
 }