I was trying to paint border around JLabel when it is clicked. Just like JButtons are painted.
I thought it would be easy but I failed to do the job.
I tried to figure out what happens to JButtons when clicked by putting breakpoints in source codes. But I got lost, however, I have a feeling that javax.swing.plaf and its subpackages are what I need.
Am I right? Is there a simpler way to do the job.
Here is an example:

You could add
MouseListenerto your label and setup a border in mousePressed/mouseReleased methods. Here is a simplified example:Also, as an alternative you can make a button with a flat style that will look like a label. This answer can be useful.