Allora ho la seguente classe InfoUtente:
codice:
package rubrica;
import javax.swing.ImageIcon;
class InfoUtente {
private String name;
private ImageIcon icon = new ImageIcon(getClass().getResource("/images/stella.png"));
public ImageIcon getIcon() {
return icon;
}
public void setIcon(ImageIcon icon) {
this.icon = icon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Riempio il listModel con un array risultato di questo metodo:
codice:
public ArrayList<InfoUtente> getArrayInfo(){
InfoUtente infoUtente = new InfoUtente();
UserProfile user = Persistence.getCurrentUserProfile();
ContactsManager contactsManager = new ContactsManager(user);
List<Contact> contactList;
String name = "";
String tel = "";
String info = "";
ImageIcon icon = null;
ArrayList<InfoUtente> cl= new ArrayList<InfoUtente>();
contactList = contactsManager.loadContacts();
for (Iterator<Contact> it = contactList.iterator(); it.hasNext();) {
Contact c = it.next();
name = c.getName();
tel = c.getTel();
info = name + " " + tel;
infoUtente.setName(info);
icon = infoUtente.getIcon();
cl.add(infoUtente);
}
return cl;
}
E mia classe CustomCell è diventata così:
codice:
class CustomRow extends JLabel implements ListCellRenderer {
//metodo (unico!) dell'interfaccia ListCellRenderer
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
InfoUtente info = new InfoUtente();
//icona da visualizzare
setIcon(info.getIcon());
//testo dell'etichetta
String s = info.getName();
setText(s);
return (this);
}
}
Mi visualizza le icone, ma non il getName dell'oggetto InfoUtente. In più credo che si tratti sempre dello stesso oggetto, ma questo è un dubbio. Quale passaggio mi sto dimenticando?