Swing's javax.swing.JList component and JavaFX's javafx.scene.control.ListView control let you customize how their various cells are rendered. In this post, I show you how to accomplish these tasks.
Customizing Cell Rendering in Swing JLists
Q: How do I customize how a JList instance's cells are rendered?
A: Swing provides the javax.swing.ListCellRenderer<E> interface to identify components that can be used as "rubber stamps" to render a JList instance's cells. This interface declares the following method:
Component getListCellRendererComponent(JList<? extends E> list,
E value,
int index,
boolean isSelected,
boolean cellHasFocus)
According to ListCellRenderer's Javadoc, getListCellRendererComponent() returns a java.awt.Component that's configured to display the specified value. The Component's paint() method is then called to render the cell.