JAVA : Préselection JComboBox

Salut à tous ,

J'ai un problème avec ma une de mes JComboBox , en fait elle contient une colonne d'une de mes tables (via un vecteur) et je voudrais qu'elle soit sur une valeur précise , mais ca foire...

mon code :

choixcategorie = new JComboBox ();
choixcategorie.setSelectedItem (modcategorie);
choixcategorie.setMaximumRowCount(3);
choixcategorie.setBounds (120, 105,200,30);
choixcategorie.setBackground(Color.WHITE);
cont.add (choixcategorie);

quand à la place de modcategorie je tape une valeur constante entre "" ca marche mais quand c'est une variable ben ca marche pas !!

si on peut me dire ce que c'est mon erreur....

D'avance merci

3 réponses

  1. Modérateur
    salut

    essaye avec ça

    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
    Throws:
    IllegalArgumentException - if anIndex < -1 or anIndex is greater than or equal to size
    1. Contributeur
      Oh! de la javadoc! En plus, celle de JComboBox!
    2. Modérateur
      la javabible, 'achement utile pour programmer ma petite mamoiselle...