编辑单元格时的行刷新 [英] Row refreshing when cell is edited

查看:129
本文介绍了编辑单元格时的行刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个JTable的问题。我编辑这样的单元格

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

然后按Enter键提交更改。在这里,我希望表gui刷新新的价值观。

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

但它们不是显示的,它们仅在我更改此类选择时显示

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

fireTableCellUpdated(inRow,inCol); 是我编辑单元格时在 tableModel 中的方法调用。

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

我不确定我是否有当fireTableCellUpdated到jtable重新绘制并重新验证时,将监听器添加到tableModel。

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

一些代码:

这个在tableModel中调用。

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


推荐答案

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

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
    }

这篇关于编辑单元格时的行刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆