I’m using a JPanel to add JComponents on and I tried to set the JPanel focusable so when the user clicks on the JPanel, it will unselect any JComponent and call that JComponent’s listener. I’ve read pretty much every Q&A asked about this and I can’t find anything that works. So then I thought: is there another container that I can use?
I’m using a JPanel to add JComponents on and I tried to set the
Share
Did you try
panel.requestFocus();? SinceJPanelis a sub class ofComponentit could also call this method. This will take focus from whatever has it at the particular moment.EDIT:
Here goes a code sample showing it working.