Forums Register Login

How to set the background color of just the text in JLabel not the icon??

+Pie Number of slices to send: Send
Hi All,
Can I change the background color of just the label text.I have an icon as well as a text String in the label.
JLabel l=new JLabel(String text, Icon icon, int horizontalAlignment)
Using l.setBackground(Color.blue)
I can set the background for the entire object----text+icon
Thanks
Pomchi
+Pie Number of slices to send: Send
If I understand that post correctly, all you need to do is:
button.setForeground(Color.whatever);
This will change the color of the text in that button.
+Pie Number of slices to send: Send
Hi Tim,
Thanks for your reply.
Let me explain my problem in detail.
I have a tree which has different components as nodes.I have radio buttons as nodes.Now I want that node to get highlighted whichever one the user selects.In the windows explorer if you notice then you'll find that just the text(file/folder name) gets highlighted on selection,not the folder icon that is displayed on to the LHS.
in my case what I have done is:
JLabel label = new JLabel("MyLabel");
label.setIcon(new ImageIcon("folder.gif"));
.....
...........
getTreeCellEditorComponent(....)
{label.setBackground(new Color(0,0,128));}
It changes the background color on selection,but changes the background of the entire label object which includes both folder icon and label text.
Hope I am more clear now.
Thx
Pomchi
+Pie Number of slices to send: Send
I can't think of any way to do it except for making the icon not transparent. That way it's background would always be the same. Of course, that might not work too well for you either.
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2097 times.
Similar Threads
Using images within a JPanel
Problem with colors on JLabels
Why can't I get this icon to show up in amy application??
Can I add radiobuttons as leaves in a JTree?
JLabel: Code for background-painting
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:01:05.