Reputation: 43
How to get the edited value of a cell in my JTable when i click the button named "save"?
Upvotes: 3
Views: 838
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
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