wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes Changing the background color on JList's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Changing the background color on JList Watch "Changing the background color on JList New topic

Changing the background color on JList's

Cameron Bruce

Joined: Jun 12, 2003
Posts: 4
Is it possible to change the background color on a JList and display alternative colors (eg. white, yellow, white, yellow,.. etc) ??
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

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 :

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
It is sorta covered in the JavaRanch Style Guide.
subject: Changing the background color on JList's
Similar Threads
need JTextField that change color when focused
Defining Highlight color of Selected Index
change the border color
how to create tablespace in java dbms
html form controls