import java.awt.Color; import java.awt.Component; import javax.swing.DefaultListCellRenderer; import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JScrollPane; public class Main { public static void main(String[] args) { Integer[] nums = { 10, 2, 5, 8, 2, 9, 2, 8, 10, 4, 6 }; JList<Integer> list = new JList(nums); list.setCellRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); Integer num = (Integer) value; if (num < 5) { setBackground(Color.RED); } return this; } }); JOptionPane.showMessageDialog(null, new JScrollPane(list)); } }