Bonjour,

j'ai un combobox avec un renderer qui va bien pour m'afficher un nom et un prenom. ex : "bob , morane".

le pb c'est que pour l'instant je l'ai fait grace à 2 String[] et que maintenant je voudrais plutôt le faire avec une classe Personne.

voici mon code (renderer):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
package loc.julien.visu;
 
import java.awt.Component;
 
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
 
public class AlternateListCellModel extends JLabel 
					implements ListCellRenderer {
 
	private String[] listNom;
	private String[] listPrenom;
 
	public AlternateListCellModel(String[] ln, String[] lp) {
		super();
	    setOpaque(true);
	    listNom = ln;
	    listPrenom = lp;
	}
 
	public Component getListCellRendererComponent(
						            JList list,
						            Object value,
						            int index,
						            boolean isSelected,
						            boolean cellHasFocus){
 
		int selectedIndex = ((Integer)value).intValue();
 
		//pour un affiche correcte
		if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }
 
		//le nom et le prenom afficher cote a cote
		setText(listNom[selectedIndex]+", "+listPrenom[selectedIndex]);		
 
		return this;
	}
}
et ma classe Peronne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
package loc.julien.visu;
 
public class Personne{
 
	private String nom = null;
	private String prenom = null;
 
	public Personne(){
		super();
	}
 
	/**
         * Créer une personne avec un nom et un prenom
         * @param n
         * @param p
         */
	public Personne(String n, String p){
		nom = n;
		prenom = p;
	}
 
	/**
         * Donne le nom de la personne
         * @return String
         */
 
	public String getNom(){
		return nom;		
	}
 
	/**
         * Donne le prenom de la personne
         * @return String
         */
 
	public String getPrenom(){
		return nom;		
	}
 
	/**
         * Entre un nom
         * @param String
         */
	public void setNom(String n){
		nom = n;
	}
 
	/**
         * Entre le prenom
         * @param String
         */
	public void setPrenom(String p){
		prenom = p;
	}
}