Salut,

J'essaie d'implémenter le système de rendu pour ma JTable mais à vrai dire, ça ne marche pas du tout !...
En fait, c'est tout simple, le rendu qu'il devrait y avoir n'a pas lieu ...

Voici le code de la classe où est créé la JTable :

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
 
public class PanelPret extends JPanel implements Observer{
 
	private JTable jTable = null;	
	TablePretModel tpm = null;
 
.....
 
	private JTable getJTable() {
		if (jTable == null) {			
			tpm = new TablePretModel();
			jTable = new JTable(tpm);
			jTable.setShowGrid(true);
			jTable.setColumnSelectionAllowed(false);
			jTable.setRowSelectionAllowed(true);
			jTable.setSelectionForeground(new Color(0, 102, 153));
			jTable.setSelectionBackground(new Color(255, 255, 204));
			jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			jTable.setDefaultRenderer(tpm.getClass(),new CellRenderer());
		}
		return jTable;
	}
 
.....
 
}
Voici le code avec le modèle pour la JTable :

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
 
public class TablePretModel extends AbstractTableModel{
 
	private static final long serialVersionUID = -8435807783031696373L;
	private SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy",Locale.US);
	private String[] header = {"Id Pret","Trader","Contrepartie","Sicav","Compartiment",
			"Titre","Quantité","Date_Début","Date_Fin","Statut","Statut_Retour"};
	private Object[][] contenu = {
			{new Integer(1),"aaa","C1","Belgacom","Cpt1","Belga",new Integer(100),
				sdf.format(new GregorianCalendar(2007,Calendar.MAY,10).getTime()),
				sdf.format(new GregorianCalendar(2007,Calendar.DECEMBER,10).getTime()),"ND","ND"},
			{new Integer(2),"bbb","C2","Belgacom","Cpt2","Belga",new Integer(3000),
				sdf.format(new GregorianCalendar(2007,Calendar.JULY,15).getTime()),
				sdf.format(new GregorianCalendar(2008,Calendar.JULY,15).getTime()),"ND","ND"}
			};
 
	public int getColumnCount() {		
		return header.length;
	}
 
	public int getRowCount() {	
		return contenu.length;
	}
 
	public Object getValueAt(int row, int col) {		
		return contenu[row][col];
	}
 
	public String getColumnName(int col) {
        return header[col];
    }
 
	public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
 
	public boolean isCellEditable(int row, int col) {        
        if (col < 9) {
            return false;
        } else {
            return true;
        }
    }
 
	public void setValueAt(Object value, int row, int col) {
        contenu[row][col] = value;
        fireTableCellUpdated(row, col);       
    }
}
Et voici le code pour le 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
 
public class CellRenderer extends JLabel implements TableCellRenderer{
 
	private static final long serialVersionUID = -6348693518838532834L;
 
	public CellRenderer(){
		super();
		setOpaque(true);
	}
 
	public Component getTableCellRendererComponent(JTable jTable, Object value, 
			boolean isSelected, boolean hasFocus, int row, int col) {				
		if (hasFocus()){
			setBackground(Color.ORANGE);
		}
		if (isSelected){
			setForeground(Color.MAGENTA);
		}			
		return this;
	}
}

Si vous voyez pourquoi ça coince, merci de faire signe