[SOLVED] Hiding a component when a user clicks outside of its bounds

EDIT: Nvm im a dummy, addMouseListener(this, true) does the trick

I have a component which basically looks/feels like a dialog, and I would like to be able to close it (hide it) when a user clicks outside of the component. What is the simplest way to do this? I have various mouseDown methods in a bunch of components, and I don’t want code spread all over the place to catch differeent mouseDown events on different components to be able to do this.

Is the only option ensuring that I have addMouseListener to every child component and sub-component in the editor to ensure that I can get an event at the editor level no matter where the user clicks?

Any help is appreciated!

Instead of a MouseListener I usually solve this by a full size component with alpha = 0.5f. This will grey out all other controls, intercept all clicks to other controls and catch the click to hide the overlay dialog.

1 Like

Thanks daniel, I do something as well in other cases but in this particular situation the dialog has no overlay