Bonsoir,

J'ai un problème tout bête... Et j'espère trouver une réponse ^^

J'ai un code tout simple, une jComboBox avec des string dedans... Enfin bon, dans le cas réel ce n'est pas ça mais aucune incidence.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
DefaultComboBoxModel model = new DefaultComboBoxModel();
jCB_Liste = new javax.swing.JComboBox(model);
model.addElement(new String("Tata"));
model.addElement(new String("Tete"));
model.addElement(new String("Titi"));
model.addElement(new String("Toto"));
model.addElement(new String("Tutu"));
model.addElement(new String("Tyty"));
Le truc, c'est qu'une fois les items ajoutés...

Je me retrouve avec une jComboBox où le premier item est sélectionné.

Mais j'aimerai vraiment qu'il soit déselectionné...

J'ai testé ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
jCB_Liste.setSelectedIndex(-1);
setSelectedIndex
public void setSelectedIndex(int anIndex)
Selects the item at index anIndex.

Parameters:
anIndex - an integer specifying the list item to select, where 0 specifies the first item in the list and -1 indicates no selection
Throws:
IllegalArgumentException - if anIndex < -1 or anIndex is greater than or equal to size
Pensant que le -1 indiquant une "non sélection" me permettrait également de déselectionner la liste...

Mais bon forcément ça ne marche pas

Avez vous une idée ?