Use panel.isVisible instead of hasParent