• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multi-colored List  RSS feed

 
Paul Fonz
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make my List object display two different colors, so that some of the items in the list appear green, and others appear blue.
Does anybody know how I could do this?
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the answer is, that you have to write your own ListCellRenderer. This yo can do either by implementing it or you extend from DefaultListCellRenderer, which is mostly the best choice. Anyway, you have to implement the method getListCellRendererComponent. In order to implement it right, you should have a look to the implementation of DefaultListCellRenderer. However, in the getListCellRendererComponent method you can set the color of your component to whatever you want.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code for how I used it. I was getting data from a database and based on the data, I chose the appropriate color. But I think you will be able to enfer what you need from this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!