我为 lwit 创建了以下自定义列表渲染器。渲染器扩展了一个复选框,但由于某种原因,选择和取消选择(选中/取消选中)功能不起作用。如果我setselected()
所有的项目都被选中并且不能被取消选中。这是示例代码;
class TaskListRenderer extends CheckBox implements ListCellRenderer {
public TaskListRenderer() {
super();
}
public Component getListCellRendererComponent(List list, Object o, int i, boolean bln) {
Tasks task = (Tasks) o;
try {
img = Image.createImage("/three.png");
} catch (IOException ex) {
ex.printStackTrace();
}
//
setIcon(img);
setText(task.getPhoneID() + " " + task.getDate());
Style style = new Style();//(0xff0000, 0x00ff00, null, byte(128));
style.setBgColor(0xff0000);
style.setFgColor(0x00ff00);
setSelectedStyle(style);
return this;
}
public Component getListFocusComponent(List list) {
return this;
// throw new UnsupportedOperationException("Not supported yet.");
}
}