Check for null before setting the zindex, and instead keep it null initially. This way calls to setZIndex() wont fail if passed null.