title: I want to show default table model total (sum) data in all cell of Total Column
body: <p>Show calculated data in all cell of the column total.</p>
  
  <p><a href="https://i.stack.imgur.com/nqBOm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nqBOm.png" alt="0 is showing in all cell of total"></a></p>
  
  <p>I don't know how to do this, when calculated it will show in all cell of the column of total.</p>
  
  <pre><code>final DefaultTableModel model = new DefaultTableModel(new String[]{"Opening", "Purchase", "Total", "Consumption"}, 10) {
      @Override
      public Object getValueAt(int row, int col) {
          Object value = null;
          switch (col) {
              case 2:
                  double opening = getAmountForRow(row);
                  double purchase = getCostForRow(row);
                  double cons=getconsForRow(row);
                  value = opening + purchase-cons;
                  break;
              default:
                  value = super.getValueAt(row, col);
          }
          return value;
      }
  
      protected double getAmountForRow(int row) {
          return getNumberForRow(row, 0);
      }
  
      protected double getCostForRow(int row) {
          return getNumberForRow(row, 1);
      }
  
      protected double getconsForRow(int row) {
          return getNumberForRow(row, 3);
      }
  
      protected double getNumberForRow(int row, int col) {
          double number = 0;
          Object value = getValueAt(row, col);
          if (value != null &amp;&amp; value instanceof Number) {
              number = ((Number) value).doubleValue();
          }
          return number;
      }
  
      @Override
      public void setValueAt(Object aValue, int row, int column) {
          if (column != 2) {
              if (aValue instanceof Number) {
                  super.setValueAt(aValue, row, column);
                  if (column == 0 || column == 1 || column==3) {
                      fireTableCellUpdated(row, 2);
                  }
              }
          }
      }
  
      @Override
      public Class&lt;?&gt; getColumnClass(int columnIndex) {
          return Double.class;
      }
  
      @Override
      public boolean isCellEditable(int row, int column) {
          return column != 2;
      }
  };
  
  final JTable table = new JTable(model);
  table.setFillsViewportHeight(true);
  table.addMouseListener(new MouseAdapter() {
      // @Override
      public void mouseClicked(MouseEvent e) {
          if (e.getClickCount() == 2) {
              if (table.rowAtPoint(e.getPoint()) &lt; 0) {
                  StringBuffer fileContent = new StringBuffer();
                  model.addRow(new Vector());
              }
          }
      }
  });
  model.addRow(new Vector());
  
  JFrame frame = new JFrame("Chemical");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(new JScrollPane(table));
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
  frame.setIconImage(null);
  frame.setSize(700,500);
  // frame.setFont(new Font("Tahoma", Font.PLAIN, 15));
  table.setFont(new Font("Tahoma", Font.PLAIN, 20));
  </code></pre>