The ListCellRenderer component also gets the object to display, and so you can format based on any logic. You can find an introduction to custom rendering here and an example of a renderer here (it sets the background based on the dnd location, but the idea is the same for different logic).
The following code gives you an idea of how it can be implemented.
class MyCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if ("TEST".equals(value)) {
source share