Renderer Jcombobox (Problème de selection)
Bonjour,
Mon objectif est d'afficher deux JLabel dans ma combobox.
Le renderer fonctionne très bien mais je n'arrive pas a sélectionner un index via la commande :
Code:
this.setSelectedItem(i);
L'index 0 est toujours selectionné.
J'imagine que j'oublie quelques choses?
Je pose ci dessous le code de mon renderer:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public MyRenderer() {
super();
//Je crée deux Jlabel que j'ajoutent à mon layout
setLayout(new GridLayout(0, 2));
for (int x = 0; x < this.lbl.length; x++) {
this.lbl[x] = new JLabel();
this.lbl[x].setOpaque(true);
add(this.lbl[x]);
}
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
//Je récupere et affichent mes deux string sous 2 jlabels
if (value != null)
this.lbl[0].setText(((String[]) value)[0]);
this.lbl[1].setText(" " + ((String[]) value)[1].replaceFirst("R_", "").toLowerCase());
}
if (isSelected)
this.lbl[0].setBackground(Color.lightGray);
else
this.lbl[0].setBackground(Color.white);
return this;
}
} |
Merci pour vos réponses