Nimesha Weerasinghe
Nimesha Weerasinghe

Reputation: 43

get edited value of cell in JTable after a button clicked

How to get the edited value of a cell in my JTable when i click the button named "save"?

Upvotes: 3

Views: 838

Answers (3)

pranay
pranay

Reputation: 2369

Maybe this should help you : table cell listener

Upvotes: 0

Line
Line

Reputation: 1651

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.

Upvotes: 0

rdonuk
rdonuk

Reputation: 3956

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();
            }

        }
    });

Upvotes: 2

Related Questions