[英]get edited value of cell in JTable after a button clicked
當我點擊名為“save”的按鈕時,如何在我的JTable中獲取單元格的編輯值?
可以從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();
}
}
});
也許這個解決方案對您來說足夠了:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
它不僅在單擊“保存”按鈕時保存所有表格數據,而且在其他焦點更改情況下也保存。
也許這應該可以幫助你: 表格單元格監聽器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.