title: Custom cells on a JTable returning wrong values (and not displaying correctly)
body: <p>I am writing a custom POS system and allowing users to change the quantity straight on the table instead of spawning a dialog box. Here's the first line of the table with dummy data in it. (I haven't linked it to a DB yet.)
  <img src="https://i.stack.imgur.com/7JZ5Z.jpg" alt="enter image description here"></p>
  
  <p><s>Price and Amt both have custom cell renderers (not that anyone can tell because they don't render right) to display a money format.</s> EDIT: I nixed the custom <em>editors</em> (not renderers, thank you) and the problem below still persists</p>
  
  <p>The plan was that when the user typed a quantity into the qty box, it would update the amt cell (and a running total at the top of the screen). To do this, I created a verifier which would verify the data was an integer and attached it to a custom cell editor that just adds the verifier to a JTextField.</p>
  
  <p>My verifier which is nested within the screen itself so it had access to the screen's fields and the table itself. I wanted to put it into the table model, but I found I couldn't tell what cell the user had selected. (Verify() works so I'm omitting that)</p>
  
  <pre><code>class QtyVerifier extends InputVerifier
  {
      private int qty = 0;
      private BigDecimal pricePerUnit;
      private BigDecimal prevamt;
  
      @Override
      public boolean shouldYieldFocus(JComponent input) 
      {
          //reset quantity
          this.qty = 0;
  
          //verify the results
          boolean ok2go = this.verify(input);
  
          if (ok2go)
          {
              //grab all the current values
              this.qty = new Integer(
                      (String)salesOrderFormTable.getValueAt(rowselected, colselected));
              this.pricePerUnit = new BigDecimal(
                      (String)salesOrderFormTable.getValueAt(rowselected, colselected));
              this.prevamt = new BigDecimal( 
                      (String)salesOrderFormTable.getValueAt(rowselected, colselected));
  
  
              //remove previous amount from the total
              addLineCostToRunningTotal(this.prevamt.negate());
              //update sales order total
              addLineCostToRunningTotal(amt);
  
              //update line total cell
              salesOrderFormTable.setValueAt(actualTotal, rowselected, 6);
              salesOrderFormTable.validate();
          }
          else { ... }
          return ok2go;
      }
  
      ....
  };
  </code></pre>
  
  <p>Here's where it gets really weird. I tell the qty that the quantity is still 1. It pulls all the proper data from the cells.</p>
  
  <pre><code>Selected: 0,1
  Quantity in cell 0,1 is 1
  Line price is 1.0
  Previous amt is 1.0
  New amt is 1.0
  </code></pre>
  
  <p>Okay, good. So I go to change the value to 5 and hit enter.
  <img src="https://i.stack.imgur.com/u9F75.jpg" alt="enter image description here">
  <s>It changes the value to 25</s> (solved this issue) and also pulls the wrong data from the cells.</p>
  
  <pre><code>Quantity in cell 0,1 is 5 //this is correct
  Line price is 5.0 //this is incorrect. It should be 1.
  Previous amt is 5.0 //also incorrect. This also should be 1.
  New amt is 25.0 //this WOULD be correct if the previous data was.
  </code></pre>
  
  <p>What is going on with my table?! Why is this giving me completely wrong information in two cells <s>and changing the qty cell to something I didn't type</s>? Is there a simpler way to do this (with or without a verifier)? I cannot have the wrong cost coming up on an order form. I considered changing all my values from doubles to BigDecimals to prevent rounding errors, but this isn't even a rounding error. It's just plain wrong. I'm completely lost now.</p>