1

I want to know why my getvalueAt() is picking old data when Enter is pressed.
I tried all update and table change modules, but I couldn't get it working. I am making an Excel sheet-like structure in JTable, in which one row updates on change to another row.

public void setValueAt(Object aValue, int row, int column) {
        if(column == 2 || column == 3 || column == 4 || column == 5)
    {
        System.out.println("2 is: "+getValueAt(row, 2));
        System.out.println("3 is: "+getValueAt(row, 3));
        System.out.println("4 is: "+getValueAt(row, 4));
        long closingbalance = Long.parseLong(getValueAt(row,2).toString())
            + Long.parseLong(getValueAt(row,3).toString())
            - Long.parseLong(getValueAt(row,4).toString());
        System.out.println("closing: "+closingbalance);
        super.setValueAt(closingbalance,row, 6);
    }               
    super.setValueAt(aValue, row, column);
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
greatmajestics
  • 1,083
  • 4
  • 19
  • 41
  • Please follow this guide lines before writing some question next time http://stackoverflow.com/editing-help. And please, please, stop the ellipsis Morse Code writing where a single dot is expected. – Joao Figueiredo Mar 29 '12 at 08:55

2 Answers2

1

Verify that your CellEditor has concluded and that your TableModel is in a consistent state when you access other values. This example override's getValueAt() to derive the dependent cell's value. To avoid so much parsing, your TableModel should probably just contain instances of Long.

Assuming you really need to override setValueAt(), it's not clear what TableModel you're using. If you're extending DefaultTableModel, the super.setValueAt() implementation is appropriate; if you're extending AbstractTableModel, the super implementation is empty, and yours will need to fire the appropriate event.

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

I can't be able to answering your question on another forum, because a new forums version driving me crazy

  • there no reason parsing value from JTable,

  • JTable implemets all important data types

  • examples here or here

  • for better help edit your question with SSCCE

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • +1 for the [default renderer/editor](http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#editrender) data types. – trashgod Mar 31 '12 at 01:08