Salut,

J'ai un JComboBox avec un renderer qui suit la javadoc:

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
 
class ColorPreviewComboBoxRenderer extends JLabel implements ListCellRenderer {
 
		Color activeCellBackground = new Color(230, 230, 230);
		Color inactiveCellBackground = Color.WHITE;
		Color activeCellForeground = Color.BLACK;
		Color inactiveCellForeground = Color.BLACK;
 
		public ColorPreviewComboBoxRenderer() {
			setOpaque(true);
			setHorizontalAlignment(LEFT);
			setVerticalAlignment(CENTER);
		}
 
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
 
		  int selectedIndex = ((Integer)value).intValue();
 
		  if (isSelected) {
		  	setBackground(activeCellBackground);
		  	setForeground(activeCellForeground);
		  } else {
		  	setBackground(inactiveCellBackground);
		  	setForeground(inactiveCellForeground);
		  }
 
		  ColorPreview icon = iconColorList[selectedIndex];
		  String colorStr = strColorList[selectedIndex];
 
		  setIcon(icon);
		  setText(colorStr);
		  setFont(new Font("Helvetica", Font.TRUETYPE_FONT, 12));
		  setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 2));
 
		  return this;
	  }
	}
Le problème qui se pose c'est que lorsque je veux récupérer les valeurs courantes avec getSelectedItem par exemple, j'ai une exception de type NullPointerException...

Est-ce une incompatibilité avec le renderer ?

(Pourtant dans la javadoc c'est fait exactement comme ici...)