This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pomchi Bedi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!