Domanda

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...

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top