简体   繁体   English

单击一个按钮后,在JTable中获取单元格的编辑值

[英]get edited value of cell in JTable after a button clicked

当我点击名为“save”的按钮时,如何在我的JTable中获取单元格的编辑值?

New value can be get from the DefaultCellEditor . 可以从DefaultCellEditor获取新值。

    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (table.getCellEditor() != null) {
                DefaultCellEditor cellEditor = (DefaultCellEditor) table.getCellEditor();
                String value = ((JTextField) cellEditor.getComponent()).getText();
            }

        }
    });

Maybe this solution will be sufficient for you: 也许这个解决方案对您来说足够了:

table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

It saves all table data not only when "save" button is clicked, but also in other cases of focus change. 它不仅在单击“保存”按钮时保存所有表格数据,而且在其他焦点更改情况下也保存。

也许这应该可以帮助你: 表格单元格监听器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM