public void validate() {
   synchronized (treeLock) {
     if ((flags & (IS_VALID | IS_ADD_NOTIFIED)) == IS_ADD_NOTIFIED) {
       // we have to descent before validating ourself
       validateTree();
       flags |= IS_VALID;
     }
   }
 }
  public void paint(Graphics g) {
    // standard JDK behavior is to paint last added childs first, simulating
    // a first-to-last z order

    validateTree();

    for (int i = nChildren - 1; i >= 0; i--) {
      Component c = children[i];

      if ((c.flags & IS_VISIBLE) != 0) {
        g.paintChild(c, (flags & IS_IN_UPDATE) != 0);
      }
    }
  }