Question

Im having problems with this JTable. I edit a cell like this

editing

Then i commit changes pressing enter. Here im hoping that table gui refresh with new values.

commit

But they aren't show, they are only show when i change selection like this

change selection

fireTableCellUpdated( inRow, inCol ); is the method call when in the tableModel when i edit a cell.

Im not sure if i have to add listener to the tableModel when fireTableCellUpdated to the jtable to repaint and revalidate.

Some Code :

This is called in the tableModel.

@Override
public void setValueAt( Object inValue, int inRow, int inCol ) {
    ProductRow productRow = (ProductRow)( getRowsData().get(inRow) );

    //more code 
    productRow.setCantidad( inValue.toString() );  // when this is called all properties are updated from ProductRow                 
    fireTableCellUpdated( inRow, inCol );
}
Was it helpful?

Solution 2

I solved it adding this at last, but im not quite sure if it's the best way to solve.

    @Override
    public void setValueAt( Object inValue, int inRow, int inCol ) {
        ProductRow productRow = (ProductRow)( getRowsData().get(inRow) );

        //more code 
        productRow.setCantidad( inValue.toString() ); // when this is called all properties of productRow are changed.                 

        //fireTableCellUpdated( inRow, inCol );// this don't refresh cause i change the row also
        //fireTableDataChanged(); - First approach. As pointed out this is wrong because it refreshes all table cells
        fireTableRowsUpdated(inRow,inRow); // adding this
    }

OTHER TIPS

If changing a particular cell updates other cells in the same row (assuming that's what you are after), your last attempt in your answer uses the correct method, just with incorrect parameter :-)

@Override
public void setValueAt( Object inValue, int inRow, int inCol ) {
    ProductRow productRow = (ProductRow)( getRowsData().get(inRow) );
    // when this is called all properties of productRow are changed.   
    productRow.setCantidad( inValue.toString() ); 
    // note: both parameters are _row_ coordinates
    fireTableRowsUpdated(inRow, inRow); 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top