我尝试更改java项目的listBox中某些项目的颜色。
我的代码:
private ArrayListModel listModelMembers = new ArrayListModel();
private ListBox listMembers;
memberList = app.members.getMembers(handle);
for (Member m : memberList) {
String display = m.getName();
listModelMembers.addItem(display, m);
}
listMembers.removeAll();
listMembers.setSelectedIndex(0);
listMembers.setModel(listModelMembers);
Font font = new Font(null, Font.ITALIC, new Extent(9, Extent.PT));
Integer i = 0;
for(DirectoryMember m: memberList){
if(m.getType() == 2){
listMembers.setSelectedIndex(i);
listMembers.setForeground(Color.LIGHTGRAY);
listMembers.setFont(font);
}
i++;
}
listModelMembers.fire();
listMembers.setSelectionMode(ListSelectionModel.MULTIPLE_SELECTION);
但我的代码会改变所有项目的颜色,而不是我想要的颜色。 如何设置好的索引元素?