1

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 );
}
4

2 回答 2

2

如果更改特定单元格会更新同一行中的其他单元格(假设这是您所追求的),那么您在答案中的最后一次尝试使用正确的方法,只是使用了不正确的参数:-)

@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); 
}
于 2013-07-16T13:38:40.783 回答
1

我最后解决了这个问题,但我不太确定这是否是最好的解决方法。

    @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
    }
于 2013-07-16T13:03:46.007 回答