@Override
        public void eventDispatched(AWTEvent event)
        {
            if (event.getID() == MouseEvent.MOUSE_PRESSED)
            {
                if (!(event.getSource() == this || event.getSource() instanceof JComponent && 
                        ((JComponent) event.getSource()).getTopLevelAncestor().equals(this)))
                {
                    this.setVisible(false);
                }
            }
        }