所做的项目,有多个地方需要根据属性值改变list列的颜色,困扰了半天终于搞定了。
public Component getListCellRendererComponent(List list, Object value,
int index, boolean isSelected) {
MailInfo mailinfo = (MailInfo) value;
title.setText(mailinfo.getTitle());
sender.setText(mailinfo.getSender());
if (mailinfo.getimportantflag().equals("重要")) {
title.getStyle().setFgColor(0xFF0000);
sender.getStyle().setFgColor(0xFF0000);
} else {
title.getStyle().setFgColor(0xFFFFFF);
sender.getStyle().setFgColor(0xFFFFFF);
}
pic.setIcon(mailinfo.getPic());
return this;
}
int index, boolean isSelected) {
MailInfo mailinfo = (MailInfo) value;
title.setText(mailinfo.getTitle());
sender.setText(mailinfo.getSender());
if (mailinfo.getimportantflag().equals("重要")) {
title.getStyle().setFgColor(0xFF0000);
sender.getStyle().setFgColor(0xFF0000);
} else {
title.getStyle().setFgColor(0xFFFFFF);
sender.getStyle().setFgColor(0xFFFFFF);
}
pic.setIcon(mailinfo.getPic());
return this;
}
一定要加else否则变成默认的颜色。