JLabel with separate text and icon background colours
Posted
by emeraldjava
on Stack Overflow
See other posts from Stack Overflow
or by emeraldjava
Published on 2010-03-25T12:30:18Z
Indexed on
2010/03/25
12:33 UTC
Read the original article
Hit count: 405
Hey,
I have a simple Jlabel element with text and icon
setting the background changes the full label colour.
I want to be able to only render the background colour on the text section of the label, ie - to have separate backgrounds/foregrounds for the icon and text. Selecting/deselecting the label will flip the colour behind the icon and text. Is this possible to do this by just extending JLabel, and if so which methods should i be looking to customise?
My alternative idea is to create a panel with two separate label elements, one with an icon the other with text. It seems a bit messy, and before i start i'm wondering is there a smarter way of achieving this with Swing.
© Stack Overflow or respective owner