Search code examples
javaswingintellij-idealistcellrenderer

Is it possible to have a different font colors on one JLabel inside in the JList?


I have a list of words in my Jlist and beside of every words are their definitions. I want that the font of the words are having a different colors than their definition. My question is that, Is it possible to have a two different colors in one Jlist?

Do I have to use ListCellRenderer?

Thanks...


Solution

  • I think you may use "<html>" style. It might look some odd but if you start your text (String value) by "<html>" (not capital letter HTML), you will be able to use html codes on your labels.

    As an example;

    new JLabel("<html><font color=red>RED</font> - <font color=navy>Navy</font></html>");
    

    Similar for JList.