简体   繁体   中英

get edited value of cell in JTable after a button clicked

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

New value can be get from the 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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