这是我的ListCellRenderer
:
public class MyListCellRendererOTP extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component cell = null;
if (value instanceof Domain) {
Domain domain = (Domain)value;
int status = domain.getStatus();
String naziv = domain.getNaziv();
int naziv1= domain.getId();
String naziv2=naziv+" "+naziv1;
ArrayList<Stavka> s=domain.getStavke();
int nasao=0;
for(int i=0;i<s.size();i++){
if(s.get(i).getTrazKol()!=s.get(i).getIzdKol()){nasao=1;}
}
cell = super.getListCellRendererComponent(list,naziv2,index, isSelected, cellHasFocus);
if(nasao==1){
cell.setBackground(Color.cyan);
}else{
cell.setBackground(Color.white);
}
if(isSelected){
cell.setBackground(Color.green);
}
}
return cell;
}
}
我有一个填充了域名的Jlist
。想法是渲染器更改行的背景,其中Domain
类的某些字段不同,如代码中所示。但由于某种原因,这不起作用。每一行都受到影响。有人可以帮忙吗?