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 50
| private class MyCellRenderer extends DefaultTableCellRenderer {
private int L, C;
private DefaultTableModel data = null;
private Integer stockFinal;
private Integer stockMax;
private DecimalFormat df;
private Double pourcentageD;
private String pourcentage;
public MyCellRenderer(int ligne, int colonne) {
super();
L = ligne;
C = colonne;
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
data = (DefaultTableModel) table.getModel();
if (column == C) {
stockFinal = (Integer) data.getValueAt(row, 2);
stockMax = (Integer) data.getValueAt(row, 3);
df = new DecimalFormat("########.00");
pourcentageD = (stockFinal.doubleValue() / stockMax.doubleValue()) * 100;
pourcentage = df.format(pourcentageD).toString() + "%";
data.setValueAt(pourcentage, row, 6);
if (stockFinal == 0) {
setBackground(noir);
setForeground(Color.WHITE);
} else {
setBackground(Color.WHITE);
}
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
return this;
}
} |
Partager