• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to change the color of the text of a JLabel  RSS feed

 
Thomas Knight
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody know how to do that? I didn't see any methods to do it.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
The easiest way is to use HTML. Go check out the swing tutorial on JLables here How to Use Labels .
Scroll down to Using HTML on a Label and read that section.
Michael Morris
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use setForeground(Color color) to do this, which I find a bit more of a JAVA way of doing it.
Either way works just the same though. But if you need to dynamically change the color of the Label, setForeground is a better option IMO.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg's way is probably is. You would have more control over how the text is diplayed since HTML is fairly limited in that regard.
Michael Morris
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!