Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 编辑单元格时刷新行_Java_Swing_Jtable_Abstracttablemodel - Fatal编程技术网

Java 编辑单元格时刷新行

Java 编辑单元格时刷新行,java,swing,jtable,abstracttablemodel,Java,Swing,Jtable,Abstracttablemodel,我对这个JTable有问题。我编辑这样的单元格 然后按enter键提交更改。在这里,我希望表gui能用新的值刷新 但它们不是显示,它们只是在我像这样更改选择时显示 firetablecell更新(inRow,inCol)是编辑单元格时在表格模型中的方法调用 当FireTableCell更新到jtable以重新绘制和重新验证时,我不确定是否必须将侦听器添加到tableModel 一些代码: 这在tableModel中被调用 @Override public void setValueAt(

我对这个JTable有问题。我编辑这样的单元格

然后按enter键提交更改。在这里,我希望表gui能用新的值刷新

但它们不是显示,它们只是在我像这样更改选择时显示

firetablecell更新(inRow,inCol)
是编辑单元格时在
表格模型中的方法调用

当FireTableCell更新到jtable以重新绘制和重新验证时,我不确定是否必须将侦听器添加到tableModel

一些代码:

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

我终于解决了,加上这个,但我不确定这是不是最好的解决方法

    @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
    }

如果更改某个特定单元格会更新同一行中的其他单元格(假设您正在执行此操作),则使用正确的方法,只是参数不正确:-)


你能给我们看一下这张表的代码吗?嗯,我不太确定我应该显示什么代码。。我发布了表格模型,当我编辑单元格时调用了该方法。这会通知表格所有单元格都已更改。这样做是错误的。请发布您的表和表模型类的代码,以及它们是如何创建的。请删除fireTableDataChanged();此通知程序将重新创建整个XxxTableModel,而不是==为了获得更好的帮助,请尽快发布SSCCE,short,runnable,compiled,dot:-)@c.s.现在我更改。。你说得对,但我不确定我是否还要继续调用
fireTableCellUpdated
@mKorbel
fireTableRowsUpdated
是坏消息?但是我不确定我是否还必须调用
fireTableCellUpdated
@nachokk“但是我收到了Object”请确认当column类声明为Integer.class时,inValue.toString()和Integer值是否存在差异,而不是两者都是Object,当然,如前所述,为了更好地帮助尽快发布SSCCE,使用XxxTableModel的硬编码值,可能是因为,可能我确信其他重要代码中还有另一个N炸弹:-)我在测试它时已经注意到+1,我忘了在这里编辑:),谢谢,请不是关于fireTableRowsUpdated(inRow,inCol)???如果他们不知何故被我的问题束缚住了,有什么不对,仍然不清楚,避免任何猜测
@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); 
}