boolean (JComponent c) { if (c.getRootPane() == null) return false; Container eachParent = c.getParent(); while (eachParent != null && eachParent.isValid()) { eachParent = eachParent.getParent(); } if (eachParent == null) { eachParent = c.getRootPane(); } eachParent.validate(); return true; }