Bonsoir;
S'il vous plait pourriez vous m'aidez pour ce problème
Ce code a toujours fait la coloration du dernier index mis à jour il écrase ne fait pas la coloration d'ancien
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 private class MyListCellRenderer extends DefaultListCellRenderer{ private int indexColor ; private JList list ; public MyListCellRenderer(JList list , int index){ this.list = list ; this.indexColor = index ; } public void setIndexColor(int index) { this.indexColor = index; this.list.repaint(); } @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if( index == this.indexColor ){ setBackground(Color.red); } return c ; } } MyListCellRenderer r = new MyListCellRenderer(jList,0); jList.setCellRenderer(r); r.setIndexColor(1); r.setIndexColor(2);//cet item qui est coloré mais le premier non
Merci d'avance pour vos réponses
Partager