Swinghacks――动感JList(三)
ectionBackground =
new Color (colorizedBackComps[0],
colorizedBackComps[1],
colorizedBackComps[2]);
// System.out.println ("fore = " +colorizedSelectionForeground);
// System.out.println ("back = " +colorizedSelectionBackground);
}
}
class AnimatedCellRenderer extends DefaultListCellRenderer {
public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean hasFocus) {
Component returnMe =
super.getListCellRendererComponent (list, value, index,
isSelected, hasFocus);
if (isSelected) {
returnMe.setForeground (colorizedSelectionForeground);
returnMe.setBackground (colorizedSelectionBackground);
/* this might be necessary if you have more
elaborate cells
if (returnMe instanceof Container) {
Component[] children =
((Container)returnMe).getComponents ();
System.out.println (children.length + " children");
for (int i=0;
(children != null ) && (i
i++) {
children[i].setForeground (colorizedSelectionForeground);
children[i].setBackground (colorizedSelectionBackground);
}
}
*/
if (returnMe instanceof JComponent)
((JComponent) returnMe).setOpaque(true);
}
return returnMe;
}
}
}