I am attempting to create a light-weight Swing GUI for a application I’m building. This is my first time using Swing, so I am not overly familiar with all of the functions or abilities quite yet. I’m running into an issue getting a specific type of behavior. Generally, when the user clicks an empty space within any of the windows/dialogs/etc that pop up, I want to deselect any components that have focus. So, like how when you have a browser open, if you are in the search bar, and then click in an empty part of the browser window, that search bar looses focus.
I have tried setting my content panels to focusable, but that didn’t seem to do anything. I also attempted to implement a clear glass pane over top of my windows, which would grab the focus if no components were underneath the click point, but that created all sorts of problems and didn’t seem to be what I was going for. Is there any kind of streamlined way to get this behavior? I use both JFrame windows and JDialog windows, so hopefully something that works for both.