private static class MyCellRenderer extends DefaultListCellRenderer { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (!(value instanceof String)) return this; if (list.getModel().getElementAt(index).toString().startsWith("!")) { setBackground(Color.orange); setForeground(Color.BLACK); } return this; } }
this.setText((String) value)
setBackground(Color.orange);setForeground(Color.BLACK);