Close Modal Window when background clicked.

Hi,
I have a modal window that I need to close when the background is clicked. Is there a way to attach a click listener to the background?
Thanks
Josh

You could add a click listener to the UI. But in this case your window couldn’t be a modal, but a simple window.

    final Window window = new Window("My window");
    addWindow(window);

    addClickListener(new ClickListener() {
        @Override
        public void click(com.vaadin.event.MouseEvents.ClickEvent event) {
            window.close();
        }
    });

Thanks Felype, but in this istance I actually do need it to be a modal. I think the best work around that I can find is the use the keyboard escape shortcut and just make sure the users now this is another option. Funny how clicking to
is too much of a hassle.