3

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

Line
  • 1,397
  • 3
  • 14
  • 39

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,841
  • 19
  • 37
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,397
  • 3
  • 14
  • 39
0

Maybe this should help you : table cell listener

pranay
  • 2,319
  • 7
  • 33
  • 56