1

I can not view each value on the same line. It is displayed per column. Every dealer in the total column line should display the sum of all values.

I do not know how to display line by line.

String[]entete= {"Revendeur/Montant","5000","3000","1500","800","600","500","400","REMISE","TOTAL","CREANCE"};
Object [][]donnees= {{"Patrick",0,0,0,0,0,0,0,0,0,""},
                     {"Marie",0,0,0,0,0,0,0,0,0,""},
                     {"Christian",0,0,0,0,0,0,0,0,0,""},
                     {"Fabian",0,0,0,0,0,0,0,0,0,""},
                     {"TOTAL",0,0,0,0,0,0,0,0,0,""}};
private void setTableModelListener() {
    tableModelListener = new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            int lastRow = model.getRowCount()-1 ;
            int lastColumn = model.getColumnCount()-2  ; //Colonne total
            int rowCount = model.getRowCount();

            if (e.getType() == TableModelEvent.UPDATE && e.getColumn() < lastColumn && e.getFirstRow() < lastRow && e.getLastRow() < lastRow ) {            
                int row = rowCount;
                int value = 0;// on initialise le résultat
                int value1 = 0;
                int value2 = 0;
                int value3 = 0;
                int value4 = 0;
                int value5 = 0;
                int value6 = 0;

                for (int i = 0; i < row; i++) {
                    value += 5000*(int) model.getValueAt(i, 1); // cumul montant
                    value1 += 3000*(int) model.getValueAt(i, 2); 
                    value2 += 1500*(int) model.getValueAt(i, 3); 
                    value3 += 800*(int) model.getValueAt(i, 4); 
                    value4 += 600*(int) model.getValueAt(i, 5); 
                    value5 += 500*(int) model.getValueAt(i, 6); 
                    value6 += 400*(int) model.getValueAt(i, 7); 
                }

                model.setValueAt(value, 0, lastColumn);
                model.setValueAt(value1, 1, lastColumn);
                }               
            }
      };
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Recay
  • 23
  • 8

1 Answers1

2

Override getValueAt() in your TableModel to return the correct value for cells in the TOTAL row and column. The correct value may be calculated by invoking getValueAt() in a loop, as shown in your TableModelListener example. In this complete example, the value shown in each row of the second column depends on the value chosen in the third column of the same row.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045