Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing the background color on JList's

 
Cameron Bruce
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to change the background color on a JList and display alternative colors (eg. white, yellow, white, yellow,.. etc) ??
Cameron.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would just create a new ListCellRenderer for the list that set the color of the background of the cell based on the index. Take a look at the WhiteYellowCellRenderer inner class in the following code :

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic