0

Is there a way to change the text color of a specific element on a JList?

like this:

one(Black)

two(Blue)

three(Black)

four(Blue)

five(Blue)

six(Black)

using a DefaultListModel and the data are coming from a DB...

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Criz
  • 77
  • 4
  • 12
  • possible duplicate of [How to generate a Jlist with alternating colors](http://stackoverflow.com/questions/1076473/how-to-generate-a-jlist-with-alternating-colors) – devrobf Sep 18 '13 at 15:17
  • Given the colors are purely alternating, note that is the default for a `JTable` when shown using the Nimbus PLAF. E.G. as seen in [this question](http://stackoverflow.com/q/11279610/418556). – Andrew Thompson Sep 18 '13 at 16:40

1 Answers1

2

The model only stores the data, not the color of the data.

You need to render the data differently for each cell. Read the section from the Swing tutorial on Writing a Custom Renderer for more information and an example.

camickr
  • 321,443
  • 19
  • 166
  • 288