public class cellule { private int code; private String valeur; public cellule(int code, String valeur) { this.code = code; this.valeur = valeur; } public String toString() { // affichera la valeur dans la combo return this.valeur; } public int getCode() { return this.code; } public String getValeur() { return this.valeur; } }
JComboBox combo = new JComboBox(); combo.addItem(new cellule(1,"toto"); // la combo affichera toto .... // récupération des valeurs : cellule c = (cellule)combo.getSelectedItem(); String val = c.getValeur(); int code = c.getCode();