Questo codice visualizza l'icona.
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) {
ImageIcon icon = new ImageIcon(getClass().getResource("/images/matita.png"));
// testo dell'etichetta
setText(value.toString());
// icona da visualizzare
if(icon != null){
setIcon(icon);
setText(" " + value.toString());
}
else
setText(value.toString() + " niente");
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
return (this);
}
}
Ma non funziona la selezione, cioè non colora l'elemento selezionato.
Se ho capito bene quello che mi dici, nel metodo che mi riempie l'array di stringhe getArrayString() , potrei passare anche l'icona? e poi nella classe CustomRow, come gli passo l'icona?