Changer la couleur de fond cellule JTable
Bonjour, je vous donne mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| package table;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Component;
import javax.swing.JTable;
import java.awt.Color;
public class cell_renderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column){
//Récupération du composant
Component cell = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
//Modifier la couleur
if(value.equals("1"))
cell.setBackground(Color.GREEN);
else if (value.equals("-1"))
cell.setBackground(Color.RED);
//Renvoi du composant
return cell;
}
} |
Code:
table.setDefaultRenderer(table.getClass(), new cell_renderer());
Ca ne marche pas et je ne vois pas pourquoi, pas d'erreurs...