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
| finalTableCellRenderer renderer = new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column);
if ( isSelected ) {
setBackground(table.getSelectionBackground());
} else if( getQuantiteDisponible(value)<0 ) {
setBackground( Color.RED );
}
else {
setBackground(table.getBackground());
}
return component;
}
};
table = new JTable(...) {
public TableCellRenderer getCellRenderer(int row, int column) {
return renderer;
}
}; |
Partager