How to generate a Jlist with alternating colors
问题 In Java how do I get a JList with alternating colors? Any sample code? 回答1: To customize the look of a JList cells you need to write your own implementation of a ListCellRenderer. A sample implementation of the class may look like this: (rough sketch, not tested) public class MyListCellThing extends JLabel implements ListCellRenderer { public MyListCellThing() { setOpaque(true); } public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean