Hi,
i have a short list of items and i'd like to set the background color of each row basing on the item type.
So i wrote a custom ListCellRenderer, but the final result is that the rows have all the same color, the one of the first item.
Here is my renderer:
public class DevicesRenderer extends Container implements ListCellRenderer {
private Label nameLabel = new Label("");
private Label typeLabel = new Label("");
public DevicesRenderer() {
setLayout(new BorderLayout());
setCellRenderer(true);
nameLabel.setUIID("ListTitle");
typeLabel.setUIID("ListSubtitle");
Container cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
cnt.addComponent(nameLabel);
cnt.addComponent(typeLabel);
addComponent(BorderLayout.WEST, cnt);
}
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
Device device = (Device) value;
nameLabel.setText(device.getDescription());
typeLabel.setText(device.getTypeId());
int color = device.getColor();
getUnselectedStyle().setBgColor(color);
getSelectedStyle().setBgColor(color);
getPressedStyle().setBgColor(color);
return this;
}
public Component getListFocusComponent(List list) {
return null;
}
public void repaint() {
}
}
Thx for any help.
(Btw, is it ok that the getListCellRendererComponent method is invoked something like 700 times for a list of only 6 items?)