无法获取正在编辑的单元格的当前值 [英] unable to fetch current value of cell being edited

查看:73
本文介绍了无法获取正在编辑的单元格的当前值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助,jtable更新给我留下了深刻的印象. 我在最后期限:(

I need help, i am struck with in jtable updation. I am on deadline :(

我有一个jtable和save按钮. 表有两列,一列是标签,另一列用于提供值. 接受输入的列具有文本字段和组合框. 当我单击保存时,表中的数据应保存在服务器端的文件中,并且同一文件是ftp,并且该文件中的数据显示在同一jtable中.

I have a jtable and save button. table has two columns, one column is labels and other column is for providing values. The column which takes input has text fields and combo boxes. When i click on save, the data from table should get saved on sever side in a file and same file is ftp and data from that file is displayed in same jtable.

问题是当我编辑一个单元格并使该单元格处于焦点状态时,未选择该值.
如果我从该单元格中删除焦点(通过选择其他不可编辑的单元格),则该值将被更新.
经过大量搜索之后,我发现了两种解决方案:
1. jtable.putClientProperty("terminateEditOnFocusLost",Boolean.TRUE);
2. jtable.getCellEditor().stopCellEditing()

The problem is when i edit a cell, and leave this cell focussed the value is not picked.
If i remove focus( by selecting other non editable cell) from that cell, the value is updated.

After googling a lot, i found two solutions:
1. jtable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
2. jtable.getCellEditor().stopCellEditing()

在调用saveData之前,我尝试了上述解决方案的很多方法和许多组合,但是这些解决方案都不是永久的. 以下解决方案在80%的时间内都有效.

I tried many things and many combinations of above solutions before calling saveData but none of the solution is permanent. below solution is working 80% of the time.

saveActionPerformed() {
    //-----------------
    if(jtable.isEditing()){
        jtable.getCellEditor().stopCellEditing();  
    } else {
        jtable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)<br>
    }
    //-------------------
    saveData(); //save data on server side and ftp the file and display again on screen<br>
}

saveData() {
//should i put opposite functions of above used code in order to put back those properties on the jtable again, for example
    dislaydata();
    jtable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)<br>
}

请让我知道可能的解决方案. 非常感谢您. 诚挚的道歉,以防止出现缩进.

Please let me know the possible solution. A very big thank you in advance. Sincere apology for poor indentation.

推荐答案

jtable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)

创建表时需要执行该语句:

That statement needs to be executed when you create the table:

JTable table = new JTable(...);
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE)

如果您在ActionListener中调用该语句,为时已晚,因为焦点已经在保存按钮上.

If you invoke that statement in your ActionListener it is too late because focus is already on the save button.

这篇关于无法获取正在编辑的单元格的当前值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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