How to get the edited value of a cell in my JTable when i click the button named "save"?
Asked
Active
Viewed 822 times
3
-
`table.getValueAt(row, column);`. – rdonuk Apr 05 '16 at 14:32
-
thanks..I tried it, but didn't work – Nimesha Weerasinghe Apr 05 '16 at 14:34
-
What it returned? Try `String value = table.getValueAt(row, column).toString();` – rdonuk Apr 05 '16 at 14:36
-
it returned old value of column. when I edit column ,it didn't returned new value – Nimesha Weerasinghe Apr 05 '16 at 14:38
3 Answers
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
-
-
I'm sorry, but I haven't create a Action listener and I don't understand how to do that.I'm very new to this – Nimesha Weerasinghe Apr 05 '16 at 14:52
-
-