For some reason hasFocus() returns true here. Use isVisible() instead as it's a stronger check anyway.