3

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

Line
  • 1,529
  • 3
  • 18
  • 42

3 Answers3

2

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

        }
    });
rdonuk
  • 3,921
  • 21
  • 39
0

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.

Line
  • 1,529
  • 3
  • 18
  • 42
0

Maybe this should help you : table cell listener

pranay
  • 2,339
  • 9
  • 35
  • 58