JTable不手动变更焦点获取新输入的值

来源:互联网 发布:php文档系统 编辑:程序博客网 时间:2024/04/30 00:20

  JTable中输入数值时,如果不变更焦点,那么新输入的值是不会保存到TableModel中的,也就是说最终无法获取新输入的值。

        现在的需求是在点击完确定按钮(JTable在一个Dialog中),而不是去手动变更焦点,就要获取新输入的值。

        解决方法是在确定按钮处理的方法内,加入table.getCellEditor().stopCellEditing();来强制结束编辑状态,最终可以通过tableModel.getDataVector()取到界面上的所有制。

        根据如下的资料获取最终的处理方法:

                http://topic.csdn.net/t/20050110/17/3714058.html

                http://zhidao.baidu.com/question/99876251.html?fr=qrl&cid=93&index=4&fr2=query


        PS:关于stopCellEditing()的注释“Tells the editor to stop editing and accept any partially edited value as the value of the editor”。

0 0
原创粉丝点击