I have a simple Jlabel element with text and icon

background setting changes the full color of the label.
I want to be able to display only the background color in the text section of the label, i.e. have separate backgrounds / front frames for the icon and text. Selecting / deselecting the label will turn the color behind the icon and text. Can this be done simply by expanding JLabel, and if so, what methods should I look for to configure?

My alternative idea is to create a panel with two separate label elements, one with an icon, the other with text. This seems a bit messy, and before I start, I wonder if there is a smarter way to achieve this with Swing.
source
share